I think this function needs an example to make any sense
Code archives/3D Graphics - Maths/PointHeightOnTri
This code has been declared by its author to be Public Domain code.
Download source code
| Gone |
;-- |
Comments
Or at least a comment on the input parameters
; Public domain code kindly supplied by RaGR (Ralph G. Roeske). Function PointHeightOnTri#(px#,pz#, x1#,y1#,z1#,x2#,y2#,z2#,x3#,y3#,z3#) e#=(x2-x1)*(z3-z1)-(x3-x1)*(z2-z1) e=1.0/e e1#=e*((x2-px)*(z3-pz)-(x3-px)*(z2-pz)) e2#=e*((x3-px)*(z1-pz)-(x1-px)*(z3-pz)) e3#=e*((x1-px)*(z2-pz)-(x2-px)*(z1-pz)) Return e1*y1+e2*y2+e3*y3 End Function Function PointInTriangle(px#,pz#, x1#,z1#,x2#,z2#,x3#,z3#) Local bc#,ca#,ab#,ap#,bp#,cp#,abc# bc# = x2*z3 - z2*x3 ca# = x3*z1 - z3*x1 ab# = x1*z2 - z1*x2 ap# = x1*pz - z1*px bp# = x2*pz - z2*px cp# = x3*pz - z3*px abc# = Sgn(bc + ca + ab) If (abc*(bc-bp+cp)=>0) And (abc*(ca-cp+ap)=>0) And (abc*(ab-ap+bp)=>0) Return True End Function
It returns the y axis position where a point in the x/z plane (at y=0) intercepts the plane of the triangle, or not, in which case it returns NAN.
so px,pz is the point and the other parameters define the triangle.
I think there is some point in triangle code elsewhere on the archives.
Ah, I see RaGR has kindly provided a point in triangle Function as well.
Sadly his original posting seems to have Gone, but for the sake of posterity and in light of his many startling and entertaining contributions over the years I think it only right it is preserved here in perpetuity.
Thanks for the commenting
;--