SyntaxBomb  Indie Coders
Languages & Coding => Blitz Code Archives => 3D Graphics  Maths => Topic started by: BlitzBot on June 29, 2017, 12:28:41 AM

Title : PointHeightOnTri
Author : RGR
Posted : 1+ years ago
Description : Gone
Code :
Comments :
CyBeRGoth(Posted 1+ years ago)
I think this function needs an example to make any sense
aab(Posted 1+ years ago)
Or at least a comment on the input parameters
DJWoodgate(Posted 1+ years ago)
; Public domain code kindly supplied by RaGR (Ralph G. Roeske).
Function PointHeightOnTri#(px#,pz#, x1#,y1#,z1#,x2#,y2#,z2#,x3#,y3#,z3#)
e#=(x2x1)*(z3z1)(x3x1)*(z2z1)
e=1.0/e
e1#=e*((x2px)*(z3pz)(x3px)*(z2pz))
e2#=e*((x3px)*(z1pz)(x1px)*(z3pz))
e3#=e*((x1px)*(z2pz)(x2px)*(z1pz))
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*(bcbp+cp)=>0) And (abc*(cacp+ap)=>0) And (abc*(abap+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.
aab(Posted 1+ years ago)
Thanks for the commenting
RGR(Posted 1+ years ago)
; [/i]