When two vectors "p" and "t" are perpendicular, they have a dot
product of zero. So if
p = p1x + p2y + p3z
and
t = t1x + t2y + t3z
then
p1t1 + p2t2 + p3t3 = 0.
If a vector is parallel to the XZ plane, its y-component is zero (it
neither rises nor falls in the y-direction). So
p2 = 0.
Plugging and chugging gives:
p1 / p3 = - t3 / t1
This blows up if t1 is zero, so check for that and use a known "p"
vector if it happens.
I'd probably use something like this:
float p1, p2, p3;
p2 = 0.0;
if (0.0 == t1) {
if (0.0 == t2 && 0.0 == t3) {
// zero length vector, anything/everything is parallel to it,
scream loudly
} else {
// original vector in XZ plane
p1 = 1.0;
p3 = 0.0;
}
} else {
// arbitrary vector, set p3 arbitrarily to 1
p3 = 1.0;
p1 = -t3 / t1;
}
Jason
On May 30, 2007, at 6:12 AM, Lorenzo wrote:
Hi,
I have to find the vector "pv" perpendicular to an arbitrary vector
"tv".
The perpendicular vector "pv" has to be parallel to the XZ (floor)
plane.
How to do it?
I have successfully found a generic perpendicular with the cross
product
between tv and a random vector rv. Of course the result is a vector
not
always laying on the XZ plane so pv[1] != 0.
So I have found this trick. Firstly I set rv = tv. Then I set rv[1]
= 0 or
rv[1] += 12345; So tv and pv lay on the same vertical plane.
So I find pv[1], that is pv is parallel to the plane XZ. Good.
The problem is that this trick doesn't work for any tv. E.g. when
tv is
{0, 1, 0} it doesn't work.
Best Regards
--
Lorenzo
email: email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/mac-opengl/smeger%
40geekspiff.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden