Slide |
Bon voilà, je voudrais determiné si un point appartient a un triangle en 3D. Je l'ai dejà fait en pour la 2D, voici mon code, qui fonctionne d'ailleur . Au faite, si vous voulez savoir pourquoi je cherche pour un triangle et pas pour d'autre forme geometrique, c'est tres simple : Un carré, un losange, un quadrlatere, ou autre, est un assemblage de triangle donc, suffit de le faire pour les triangles, est de decoupé les otres formes en triangle
Bon, voilà donc le code que j'ai fait pour l'axe X et Y. Il ne manque que l'axe des Z maintenant... //------------------CODE------------------ type TSpacePoint = packed record X: Double; Y: Double; Z: Double; end; function TForm1.CollisionTriangulisation(Const X,Y : Double; Const point1,point2,point3:TSpacePoint):boolean; var CoeffA1,PtsOrigineB1,Ycomp1; Double; CoeffA2,PtsOrigineB2,Ycomp2; Double; CoeffA3,PtsOrigineB3,Ycomp3; Double; point1c,point2c,point3c,pointT:TSpacePoint; begin point1c:=point1; point2c:=point2; point3c:=point3; If ((point1.x<point2.x)) then begin pointT:=point1c; point1c:=point2c; point2c:=pointT; end; //ax+b=y CoeffA1:=((point1c.y-point2c.y)/(point1c.x-point2c.x)); PtsOrigineB1:=(point2c.y-((point1c.y-point2c.y)/(point1c.x-point2c.x))*point2c.x); CoeffA2:=((point2c.y-point3c.y)/(point2c.x-point3c.x)); PtsOrigineB2:=(point3c.y-((point2c.y-point3c.y)/(point2c.x-point3c.x))*point3c.x); CoeffA3:=((point3c.y-point1c.y)/(point3c.x-point1c.x)); PtsOrigineB3:=(point1c.y-((point3c.y-point1c.y)/(point3c.x-point1c.x))*point1c.x); Ycomp1:=CoeffA1*X+PtsOrigineB1; Ycomp2:=CoeffA2*X+PtsOrigineB2; Ycomp3:=CoeffA3*X+PtsOrigineB3; result:=false; If ((point3c.y>point1c.y) or (point3c.y>point2c.y)) then If (((point1c.x>point3c.X) and (point2c.x<point3c.x) and (Y>Ycomp1) and (Y<Ycomp2) and (Y<Ycomp3)) // + milieu or ((point1c.x<point3c.X) and (Y>Ycomp1) and (Y<Ycomp2) and (Y>Ycomp3)) // + droite or ((point2c.x>point3c.X) and (Y>Ycomp1) and (Y>Ycomp2) and (Y<Ycomp3))) // + gauche then result:=true; If ((point3c.y<point1c.y) or (point3c.y<point2c.y)) then If (((point1c.x>point3c.X) and (point2c.x<point3c.x) and (Y<Ycomp1) and (Y>Ycomp2) and (Y>Ycomp3)) // + milieu or ((point1c.x<point3c.X) and (Y<Ycomp1) and (Y>Ycomp2) and (Y<Ycomp3)) // + droite or ((point2c.x>point3c.X) and (Y<Ycomp1) and (Y<Ycomp2) and (Y>Ycomp3))) // + gauche then result:=true; end; //------------------CODE------------------ Je ne pense pas obtenir de l'aide, car ce probleme est complexe, mais, j'essai quand meme de poser ma question ici, on sait jamais que quelqu'un m'aide
Au faite, me renoyer pas sur www.google.com ou sur une otre page du genre, moi je veux le faire moi meme ;p , ou avec votre aide.
|