#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "structures.h"
#include "prototypes.h"



void normalise (Vecteur *v)
{
    double mag = 0.0;

    if (v->x != 0 && v->y != 0 && v->z != 0)
    {
        mag = sqrt(v->x*v->x + v->y*v->y + v->z*v->z);

        v->x = (v->x)/mag;
        v->y = (v->y)/mag;
        v->z = (v->z)/mag;
    }


}


Vecteur produitVectoriel (Vecteur v1, Vecteur v2)
{
    Vecteur resultat;

    resultat.x = (v1.y * v2.z) - (v1.z * v2.y);
    resultat.y = (v1.z * v2.x) - (v1.x * v2.z);
    resultat.z = (v1.x * v2.y) - (v1.y * v2.x);

    return resultat;
}


double calculDistance (Coordonnees p1, Coordonnees p2)
{
    double distance = 0.0;
    distance = sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) + (p1.z-p2.z)*(p1.z-p2.z));
    return distance;
}


double calculAngle (Vecteur v1, Vecteur v2)
{
    double angle = 0.0;
    angle = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
    return angle;
}


int estIdentique (Objet obj1, Objet obj2)
{
    if (obj1.type == obj2.type && obj1.index == obj2.index)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}



int appartientAuPlan (Vecteur normal, Coordonnees pointPlan, Coordonnees pointAChercher)
{
    double a = 0.0, b = 0.0, c = 0.0, d = 0.0, equation = 1.0;

    a = normal.x;
    b = normal.y;
    c = normal.z;
    d = -(a*pointPlan.x + b*pointPlan.y + c*pointPlan.z);

    equation = (a*pointAChercher.x + b*pointAChercher.y + c*pointAChercher.z + d);

    if (equation == 0.0)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}






