# basic vector question

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

## 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 on other sites
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 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 Zoombywhat 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 on other sites
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 on other sites
Quote:
 Original post by Zoombythanks! 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 on other sites
Quote:
 Original post by Zoombyhi!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 on other sites
Quote:
 Original post by ZoombyI 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 on other sites
Quote:
 Original post by Zoombythanks! 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 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 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 on other sites
Quote:
 Original post by Zoombyis 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?

Basically yes, but you have to be careful. Let's say that we are using the vector w instead of b and get:

x = Dot( u, w ) / Dot( b, w )

If w = (1,1,1) and b = (-1,1,0), we get Dot( w, b ) = 0. This is bad since we are dividing by zero.

There are two reasons for choosing b. First, is that Dot( b, b ) = 0 iff b = 0.
The second one is even more interesting:

Let's say that we have c, such that u and b are not colinear, that is c does not lie on the line defined by a and b.

If we find x by dotting with b and substitute it into the line equation, we get:
c' = a + x*b.

It appears that this c' is the closest point to c in the least squares sense.
Or in other words, of all points on the line, c' is the closest point to c.

Edit: Sorry haegarr, missed your post. Thank you for showing why the "second reason" is correct.

[Edited by - ury on January 21, 2006 1:35:43 PM]

##### Share on other sites
Do I miss something? Please correct me if I'm wrong, but:

Quote:
 Original post by Zoombyis 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?

Neither are u (P-R0 in my somewhat detailed post above) and b (t) linearly dependent in general, nor could an arbitrary vector be used.

To clarify this I've introduced x in the post above, showing that there is another distance vector involved. The dependency would be given if and only if P is definitely lying on R(s), but that isn't given in general (furthurmore it is the _unknown_ here).

Your b is the track of the ray, and hence the denominator could not become zero or else there is no ray/line at all!

EDIT:
Quote:
 Original post by urySorry haegarr, missed your post.

No problem :)

##### Share on other sites
Quote:
 Original post by haegarrDo I miss something? Please correct me if I'm wrong, but:Neither are u (P-R0 in my somewhat detailed post above) and b (t) linearly dependent in general, nor could an arbitrary vector be used.

Well, it really depends on what you are trying to achieve. If the vectors are colinear, that is P = R(s), then any vector would do (as long as you don't divide by zero). This has only a theoretical value though since in practice using the vector b is the best choice.

BTW, if I am not mistaken, the vectors are colinear in OP's question.

##### Share on other sites
Quote:
 Original post by uryIf the vectors are colinear, that is P = R(s), then any vector would do (as long as you don't divide by zero). This has only a theoretical value though since in practice using the vector b is the best choice.BTW, if I am not mistaken, the vectors are colinear in OP's question.

Yes, that's right. The confusion is caused from the fact that the OP doesn't formulate the actual problem (say point on a ray) but a nearby and more general problem. For the latter one the limitations you've mentioned hold, but for the former one they don't. So we really discuss about theoretical issues :)