Ooops
November 25, 2020, 08:07:51 AM

Author Topic: [bb] PointHeightOnTri by RGR [ 1+ years ago ]  (Read 598 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] PointHeightOnTri by RGR [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : PointHeightOnTri
Author : RGR
Posted : 1+ years ago

Description : Gone

Code :
Code: BlitzBasic
  1. ;--


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)

 
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*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.


aab(Posted 1+ years ago)

 Thanks for the commenting


RGR(Posted 1+ years ago)

 ;-- [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal