# SyntaxBomb - Indie Coders

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

Title: [bb] PointHeightOnTri by RGR [ 1+ years ago ]
Post by: BlitzBot on June 29, 2017, 12:28:41 AM
Title : PointHeightOnTri
Author : RGR
Posted : 1+ years ago

Description : Gone

Code :
Code: BlitzBasic
1. ;--

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)

Code: [Select]
`; 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*y3End FunctionFunction 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 TrueEnd 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]
SimplePortal 2.3.6 © 2008-2014, SimplePortal