Skip to main content
gamedev.net
🔒 Locked

Vector question

Started by CProgrammer 3 replies 300+ views
Original Post
CProgrammer
CProgrammer
Say i have 2 3d-Vectors. How do i get a vector specifying the part of the second vector that intersects the first diagonally. Vector a, b; vector b goes through a in a certain angle(however 3d). I need the vector that specifies the direction and power of b hitting a orthogonally(90degrees) -CProgrammer
LilBudyWizer
LilBudyWizer
The component of B along A is A.B/|A|. The dot product is |A||B|cos(t) and the magnitude of A/|A|=1 so it is |B|cos(t) which is the length of the adjacent side of a right triangle with hypotheneus |B|. The projection of B onto A is ((A.B)/(A.A))*A. Component seems to be used loosely with it sometimes being a vector and sometimes a scalar. The projection of B onto A is often referred to as the component of B parallel to A. If you subtract that from B you get the component perpendicular to A.
Keys to success: Ability, ambition and opportunity.
CProgrammer
CProgrammer
Possibly you could give me a short code snippet calculating this with Vectors
Vector A(x, y, z);
Vector B(x2, y2, z2);
Vector result;

Because i dont quite understand what you are reffering to with A.B and t. May be my little knowledge of vectors.

Thanks in advance.

-CProgrammer
LilBudyWizer
LilBudyWizer
Sorry, in A.B the "." is the dot product and |A| means the magnitude of B. So if A=(a1,a2,a3) and B=(b1,b2,b3) then A.B/|A| is (a1*b1+a2*b2+a3*b3)/sqrt(a1*a1+a2*a2+a3*a3). "t" is the angle between the two vectors. Generally you just use the fact that A.B=|A||B|cos(t) to understand what is going on. You need the value of cos(t), not t itself.

Here is an explanation of the dot product if you need it. Note the "^" above the Y in the diagram. That means it is a unit vector which means its magnitude is 1 so there is no need to divide by it. A/|A| is a unit vector in the direction of A.
Keys to success: Ability, ambition and opportunity.
CProgrammer
CProgrammer
Oh Ok
Thanks for the help. Appreciate it.

-CProgrammer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.