Forum » » Création-Développement » » Question math 3D
Posté : 05-09-2013 15:26
Avec des macros pour éviter les (mes) fautes de frappe et faire plus joli:
==============================================
Vertex3D A,B,V;
Vertex3D AV,AB,P;
float h2,h,x;
#define DIST2(V) (V.x*V.x + V.y*V.y + V.z*V.z)
#define PSCAL(A,B) (A.x*B.x + A.y*B.y + A.z*B.z)
AV.x =V.x - A.x;
AV.y =V.y - A.y;
AV.z =V.z - A.z;
AB.x =B.x - A.x;
AB.y =B.y - A.y;
AB.z =B.z - A.z;
P.x=AV.y*AB.z - AV.z*AB.y;
P.y=AV.z*AB.x - AV.x*AB.z;
P.z=AV.x*AB.y - AV.y*AB.x;
h2 = DIST2(P) / DIST2(AB);
h = sqrt(h2);
x = sqrt( DIST2(AV) - h2)
if( PSCAL(AV,AB ) <0)
x=-x;
Cet article provient de Le site des utilisateurs francophones actuels et futurs d'AmigaOS 4.x
https://amiga-ng.org/viewtopic.php?topic=1651&forum=14