a bit shorter and about 15% faster (using less locals each time the function is called)
Disabling the "Distance# var" and enabling the local again cuts the speed to 52/58 instead of 50/58.
Using a^2 instead of a*a is instead a reason to be 300% as slow as the original code.
bye
MB
Function Magnitude#( px#,py#,pz#,dx#,dy#,dz# ) Return Float(Sqr( (dx# - px#)*(dx# - px#) + (dy# - py#)*(dy# - py#) + (dz# - pz#)*(dz# - pz#) )) End Function Function DistancePointLine( ax#,ay#,az#,bx#,by#,bz#,px#,py#,pz#, Distance# Var) Local LineMag#,U# Local ix# = bx# - ax# Local iy# = by# - ay# Local iz# = bz# - az# ' Local Distance# LineMag# = Magnitude( bx#, by#, bz#, ax#, ay#, az# ) U# = ( ( ( px# - ax# ) * ix# ) +( ( py# - ay# ) * iy# ) +( ( pz# - az# ) * iz# ) ) /( LineMag# * LineMag# ) If U# < 0.0 Or U# > 1.0 Then Return False ' closest point does Not fall within the line segment ix# = ax# + U# * ix# iy# = ay# + U# * iy# iz# = az# + U# * iz# Distance# = Magnitude( px#,py#,pz#,ix#,iy#,iz# ) Return True End Function
Disabling the "Distance# var" and enabling the local again cuts the speed to 52/58 instead of 50/58.
Using a^2 instead of a*a is instead a reason to be 300% as slow as the original code.
bye
MB