Jump to content
  • Advertisement
Sign in to follow this  
Zoomby

basic vector question

This topic is 4565 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi! a, b are vectors, s is a scalar. if a * s = b then b/a = s. Is vector-division possible? Or, how can I get s from a and b, what if a contains zero(s)? bye, Chris

Share this post


Link to post
Share on other sites
Advertisement
Vector division wouldn't tell you anything, so no, it's not possible. Remember, a vector is two parts: a magnitude (length) and a direction (angle). Scaling a vector (a * s) only affects a vector's magnitude (length). You can multiply or divide a vector by a scalar value, but it only changes its length, not its direction.

As for getting a scalar s from vectors a and b, you can only do that by transforming one of the vectors so that it's pointing in the direction of the other, then it's a matter of dividing |a|/|b| (|a| indicates the vector's magnitude (length)).

Share this post


Link to post
Share on other sites
The formula of theOP is not correct since such kind of operation isn't defined.

Notice that there is another dependency in your case. With
a * s = b
you express b being a scaled version of a, so that their directions are the same (or opposite) but their lengthes are not:
||a|| * |s| = ||b||
From this relation
|s| = ||b|| / ||a||
(as long as ||a|| differs from null) and the sign could be determined from the sign of the dot-product
a . b

Quote:
Original post by Zoomby
what if a contains zero(s)

From math you could not determine whether a or else s or else both were zero when looking at the product's result b only. If a is zero in my formula above than s could be anything in-between infinity and minus infinity, and the equation still holds.


EDIT: Once more too late :(

Share this post


Link to post
Share on other sites
thanks! Why I asked it:
I want to check if a point is on a line.
the equation is c = a + x * b, where c is the point and (a + x * b) is the line. So how can I find x?
x = c - a / b would not make sense because of the division?

Share this post


Link to post
Share on other sites
Quote:
Original post by Zoomby
thanks! Why I asked it:
I want to check if a point is on a line.
the equation is c = a + x * b, where c is the point and (a + x * b) is the line. So how can I find x?
x = c - a / b would not make sense because of the division?


You don't need vectors for a point on the line;

say you have a point: (m, n), and you want to know if it's on the line y = ax + b, all you have to do is plug in (m) for x and solve. if y is equal to n, then the point is on the line. If not, the point is not on the line.

so:


if ( (n) == a *(m)+ b )
return true;
else
return false;


Share this post


Link to post
Share on other sites
Quote:
Original post by Zoomby
hi!
a, b are vectors, s is a scalar.
if a * s = b then b/a = s.

Is vector-division possible? Or, how can I get s from a and b, what if a contains zero(s)?

bye,
Chris


Vector division is undefined. You can still obtain s from just a and b, however.

Multiplication of a vector by a scalar results in a scaling of the magnitude only. s, then, is that number such that s*|a| = |b|. Thus, s = |b|/|a|.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zoomby
I want to check if a point is on a line.


If we define:
u = c - a
v = b - a

then point c lies on the line if u and v are colinear. That is if:
Dot(v,v)*Dot(u,u) = Dot(u,v)2
(This is a direct result of the Cauchy-Schwarz inequality.)

The check can be performed even faster in 2d (this can be done if you carefully project your problem to 2d) like this:
Assuming that u and v are 2d vectors, they are colinear if:
u.x * v.y = u.y * v.x
(Derived from the determinant of a 2x2 matrix containing u and v)

Quote:

the equation is c = a + x * b, where c is the point and (a + x * b) is the line. So how can I find x?


Like this:
c = a + x * b ,

subtract a:
u = x * b,

dot both sides with b:
Dot( u, b ) = x * Dot( b, b )

And get:
x = Dot( u, b ) / Dot( b, b )

(Once again, it can be optimized if carefully projected to 2d)

Nilkn, you are only partially correct. Please read haegarr's post more carefully.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zoomby
thanks! Why I asked it:
I want to check if a point is on a line.
the equation is c = a + x * b, where c is the point and (a + x * b) is the line. So how can I find x?
x = c - a / b would not make sense because of the division?


You said b is just a scaler? If in expanded form you mean this:

[c1] [a1] [x1]
[c2] = [a2] + [x2]b
[c3] [a3] [x3]

Then you can solve it like this:
[(c1-a1)/b] [x1]
[(c2-a2)/b]= [x2]
[(c3-a3)/b] [x3]

If, however, b is also a vector, say like this:
[c11 c12 c13] [a11 a12 a13] [x11 x12 x13][b11 b12 b13]
[c21 c22 c23] = [a21 a22 a23] + [x21 x22 x23][b21 b22 b23]
[c31 c32 c33] [a31 a32 a33] [x31 x32 x33][b31 b32 b33]

Then you need to do this:
(C-A)B^-1 = X

Where B^-1 is the inverse of B. This is the closest thing to division you can do. For more information on the inverse of a matrix there are plenty of online resources to help with calculating it.

Share this post


Link to post
Share on other sites
thanks ury!
is it true that is doesn't matter with which vector I do the dot product, since u and b are linearly dependent? So the vector (1 1 1) could be used?

Share this post


Link to post
Share on other sites
I would like to give some details here:

The line (better a ray) is defined as all points
R(s) := R0 + s * t
where R0 is any point on the ray, and t denotes the track of the ray.

A point P anywhere in space could be expressed by traveling along the ray until coming close as possible to P and then going an unknow step to actually reach P:
P = R0 + s' * t + x

Here x is perpendicular to t, or else the reached point on the ray wouldn't be closest.

This formula should be solved for the particular s'. Using ury's method yields in
( P - R0 ) . t = s' * t . t = s' * ||t||2
since
x . t == 0
due to perpendicularity, and after some re-arranging
s' = ( P - R0 ) . t / ||t||2
(what ury has already stated). This formula computes the difference vector of R0 to P and projects it onto the t.

So s' is the travel distance onto the ray but is not yet the solution of the problem. To finish, one has to check
x = P - R(s') == 0
within some finite resolution. If so, P lies on the line. In general P is ||x|| length units away from the line.

EDIT: 0 denotes the zero vector here.

[Edited by - haegarr on January 21, 2006 2:13:59 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!