1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| struct Point {
float x;
float y;
float z;
};
struct Point pointA;
struct Point pointB;
struct Point pointC;
struct Vecteur {
float x;
float y;
float z;
};
struct Vecteur vecteurAB;
struct Vecteur vecteurAC;
struct Normale {
float x;
float y;
float z;
};
struct Normale normale;
struct Direction {
float x;
float y;
float z;
};
struct Direction direction;
float magnitude;
// A(0, 1, 1)
pointA.x = 0.0f;
pointA.y = 1.0f;
pointA.z = 1.0f; // hauteur
// B(1, 1, 2)
pointB.x = 1.0f;
pointB.y = 1.0f;
pointB.z = 2.0f;
// C(0, 0, 1)
pointC.x = 0.0f;
pointC.y = 0.0f;
pointC.z = 1.0f;
// Y
// ^
// | ->
// |
// _______>X
direction.x = 1.0f;
direction.y = 0.0f;
direction.z = 0.0f;
vecteurAB.x = pointB.x - pointA.x;
vecteurAB.y = pointB.y - pointA.y;
vecteurAB.z = pointB.z - pointA.z;
printf ( "vecteurAB x=%f, y=%f, z=%f\n", vecteurAB.x, vecteurAB.y, vecteurAB.z );
vecteurAC.x = pointC.x - pointA.x;
vecteurAC.y = pointC.y - pointA.y;
vecteurAC.z = pointC.z - pointA.z;
printf ( "vecteurAC x=%f, y=%f, z=%f\n", vecteurAC.x, vecteurAC.y, vecteurAC.z );
// Calcul de la normale
normale.x = ( vecteurAB.y * vecteurAC.z ) - ( vecteurAB.z * vecteurAC.y );
normale.y = ( vecteurAB.z * vecteurAC.x ) - ( vecteurAB.x * vecteurAC.z );
normale.z = ( vecteurAB.x * vecteurAC.y ) - ( vecteurAB.y * vecteurAC.x );
printf ( "Normale x=%f, y=%f, z=%f\n", normale.x, normale.y, normale.z );
// Normalisation du vecteur ( Norme = 1 ) ???
magnitude = sqrt ( normale.x * normale.x + normale.y * normale.y + normale.z * normale.z );
normale.x /= magnitude;
normale.y /= magnitude;
normale.z /= magnitude;
printf ( "Normale normalise x=%f, y=%f, z=%f\n", normale.x, normale.y, normale.z ); |
Partager