## Projecting one vector onto another... why?

Moderator
Posts: 712
Joined: 2002.04
Post: #1
Okay, I'm currently working through Dunn & Parberry's 3D Math Primer, and I've just come to a topic which has me totally lost; the book has a short topic on projecting one vector, 'v', onto another, 'n', splitting the vector v into two two sub-vectors, 'v-parallel-to-n' and 'v-perpendicular-to-n'.

For retrieving 'v-parallel-to-n', the book gives the formula:

I've worked through a few examples to try to gain an understanding of the workings of this formula (and the related formula for retrieving 'v-perpendicular-to-n'), but I'm lost; the topic seems to be presenting an overly complex method for retrieving either the x or y component of the vector 'v', simply returning a copy of 'v' with the unwanted component negatedâ€¦

I'm just at a loss as to what I'm supposed to be achieving with these formulas? If somebody could throw some light on this topic? (Preferably using short, easy to understand words )

The first example I worked through:

Mark Bishop
--
Student and freelance OS X & iOS developer
Moderator
Posts: 387
Joined: 2002.08
Post: #2
From what I remember from Calc 3, it's essentially a way to find the portion of a vector that lies in the same direction.

If the dot product is 0, the vectors are in no way in the same direction. (perp.)

It's not just an x,y component, but rather components in relation to the vector.

Can someone verify that's correct? That wasn't a great explanation, but it's a start.

KB Productions, Car Care for iPhone/iPod Touch
@karlbecker_com
All too often, art is simply the loss of practicality.
Moderator
Posts: 1,563
Joined: 2003.10
Post: #3
If I correctly understand what you're trying to do, I might be able to help. This is a small test application I wrote a little while ago that projects one vector onto another. (Click and drag to move the target, option-drag and shift-drag to move the line.) Let me know if this is what you're looking for, and I'll explain how it works.

- Alex Diener
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
The formula is n * (whatever) and the whatever will always be a scalar value, so the result of the formula will be the vector n scaled by the value.

looking at v.n / |n*n| is similar to v.n / |n*v| (= cos(a))
so in terms of cos(a)

(v.n)/(|n||v|)=cos(a)
(v.n)/(|n||n|)=( |v| / |n| ) cos(a)

so the scalar is (the ratio of the lengths of vectors v to n) * ( cos(a) )

from this:
the length of the resultant vector will be larger if v is larger than n
and because a will always be less than 180 degrees, as the angle between the vectors increase the length of the resultant vector will decrease.

Thats just the way i view it though..
Moderator
Posts: 529
Joined: 2003.03
Post: #5
I have this book at home somewhere. What page is this on?

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Member
Posts: 57
Joined: 2002.04
Post: #6
sealfin Wrote:the topic seems to be presenting an overly complex method for retrieving either the x or y component of the vector 'v'

In this example, projn v (the projection of v onto n) is the x component of v since n is parallel to the x axis. If n were, for example, (1, 1), projn v would equal (4, 4), a vector at the same angle as n whose magnitude is the "component" of v parallel to n.

To break down the formula a bit: n*(v.n)/(|n|^2) can be rewritten as (n/|n|)*(v.(n/|n|)); the |n|^2 in the denominator normalizes both uses of the n vector. Since a.b = |a|*|b|*cos(theta), v.(n/|n|) = |v|*cos(theta), which is the magnitude of the resulting vector. Essentially, what you're doing is constructing a right triangle with v as the hypotenuse and projn v as the leg adjacent to theta. Since cos(theta) = adj./hyp. in right-triangle trig, the length of the adjacent side (|projn v|) equals the length of the hypotenuse (|v|) times cos(theta). Thus the (v.(n/|n|)) bit gives you the magnitude of the projected vector; multiplying this by n/|n| points it in the direction of vector n.

Hopefully that makes at least a little sense; it's a bit hard for me to explain without pretty pictures and/or wild gesticulations.
Moderator
Posts: 712
Joined: 2002.04
Post: #7
@Daniel_Lurie: page 61 (plus a .pdf of corrections from the web-site of the book...)

Mark Bishop
--
Student and freelance OS X & iOS developer
Sage
Posts: 1,403
Joined: 2005.07
Post: #8
Mazilurik, thats what i meant but put much better
Moderator
Posts: 712
Joined: 2002.04
Post: #9
Thanks for the help so far, I'm trying vainly to follow everybody's help on this But I'm now even more lost than before, if that were possible... According to the explanation given in the book, 'v-odd,-inverted-T' is the vector perpendicular to 'n'.
I've tried working through several examples, but none of them result in a 'perpendicular'/'v-odd,-inverted-T' vector anywhere close to 90Â° from 'n'. Is this correct, and Dunn and Parberry have a revolutionary new definition of perpendicular I haven't heard of?

Mark Bishop
--
Student and freelance OS X & iOS developer
Member
Posts: 57
Joined: 2002.04
Post: #10
Those values for VII seem off; the magnitude of the projection shouldn't be greater than that of the original vector. According to my math:

VII = (3, -2) * ((3, 1).(3, -2))/|(3, -2)|^2
= (3, -2) * (9-2)/(âˆš(9+4))^2
= (3, -2) * 7/13
= (21/13, -14/13) ~= (1.615, -1.077)

And for the perpendicular (projection onto vector orthogonal to n):

Vp = (2, 3) * ((3, 1).(2, 3))/|(2, 3)|^2
= (2, 3) * (6+3)/13
= (18/13, 27/13) ~= (1.385, 2.077)
Moderator
Posts: 529
Joined: 2003.03
Post: #11
I am wondering what in 3D this would be used for...other than figuring the distance to the picture plane...

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Moderator
Posts: 712
Joined: 2002.04
Post: #12
@Mazilurik: right, I'm printing your post and settling in for a long night in front of the calculator

@Daniel_Lurie: I'm likewise wondering, but the book says the formula will be used later, so I'd like to understand it before I move on... It's just annoying that the (for myself) most complex math in the book thus far has the shortest explanation

Mark Bishop
--
Student and freelance OS X & iOS developer
Moderator
Posts: 529
Joined: 2003.03
Post: #13
sealfin Wrote:@Daniel_Lurie: I'm likewise wondering, but the book says the formula will be used later, so I'd like to understand it before I move on... It's just annoying that the (for myself) most complex math in the book thus far has the shortest explanation

I have no doubt that if you see it in the context of what's done with it, the light bulb in your head will go off. I say ignore the frigging thing for the moment.

It may make more sense when you see how they do it in code anyway.

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Sage
Posts: 1,403
Joined: 2005.07
Post: #14
yeah, absolutly please tell us what it used for later
Moderator
Posts: 443
Joined: 2002.09
Post: #15
I've always found it easiest to think of it in terms of basic trig.

cos() of a triangle's angle is the "length(adjacent)/length(hypotenuse)". So if you know the cos() of the angle already, and the length of the hypotenuse, you can easily figure out the length of the "adjacent" side of the triangle.

And the dot product is simply a vector math equivalent of cos().

So what is it used for? As funkboy wrote, "it's essentially a way to find the portion of a vector that lies in the same direction [as a 2nd vector]."

- If the 2nd vector is perpendicular to the ground, you can use this to compute the "bounce" of a moving object against the ground. The object keeps moving sideways but the "up-down" movement is reversed.
- Similarly, you can figure out how heavily an object is pushing against a slanted or flat surface, to compute friction.
- I've used it to figure out the impact point of a sphere moving along a vector and passing close to a plane, or another sphere.

Etc. It comes up a lot.

Measure twice, cut once, curse three or four times.