parallel lines

BlitzMax Forums/BlitzMax Programming/parallel lines

Difference(Posted 2005) [#1]
If a vector cross product zero , the vectors are parallel right?
But what's a good value for messuring that the product is zero?

If (cx>0.00001) And (cy>0.00001) And (cz>0.00001) ?
Short and long vectors will not have the same 'parallellity tolerance' :)

Should I calculate the magnitude first and do something like:

If (cx>0.00001*mag) And (cy>0.00001*mag) And (cz>0.00001*mag) ?

But the magnitude would be close to or zero also, so I'd have to check that against another threshold first. What threshold?


Chris C(Posted 2005) [#2]
you'd need abs(cx) wouldnt you? to capture small -tive values


Michael Reitzenstein(Posted 2005) [#3]
I haven't really tested this extensively, but if I were trying to find parallel lines I'd do something like this:

Local ax# = 1.0, bx# = -2.0
Local ay# = 2.0, by# = -4.0
Local az# = 3.0, bz# = 6.0

Local ratiox# = ( ax / bx )
Local ratioy# = ( ay / by )
Local ratioz# = ( az / bz )

Local ratioxy# = ( ratioy / ratiox )
Local ratioxz# = ( ratioz / ratiox )

If ( 0.9999 < ratioxy )

If ( 1.0001 > ratioxy )

If ( 0.9999 < ratioxz )

If ( 1.0001 > ratioxz )

Print "parallel"

EndIf

EndIf

EndIf

EndIf



Difference(Posted 2005) [#4]
thx, but I'm looking for cross product test.
I got another suggestion on IRC on normalising the cross vectors first. That seems like a good idea, to get an even compare.

Meanwhile I coded myself out of needing to test for parallel lines :)


Michael Reitzenstein(Posted 2005) [#5]
A ratio test is faster and simpler. A cross product test has a cool, clever sounding name. Both do the same job. Take your pick.