# Sliding vector from velocity vs a wall

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

## Recommended Posts

Or whatever you want to call it... I'll make my case clear with this drawing: W is a wall along which I want to slide the purple object. The object has velocity vector A and I want to know the sliding vector C. I know C definitely does not have the same length as A and I know C = A + B, but the question is, how do I find B without knowing C? I have read the articles on collision detection around here and they did not gave me a clear answer, thus my post here, I hope someone can help ;) I tried using the normal of W scaled to the length of A, and got close, but then C is not the accurate sliding vector (its direction is a little off) so that can't be the correct math.

##### Share on other sites
You could split A into a part perpendicular to the wall (I assume that is what you meant with B) and a part C along the wall.

With N being the (unit length) normal of the wall, pointing into the room where the object is, then
N dot -A := -1 * ||A|| * cos<N,A>
will result in the projected length of A against N. Hence
B := A * ( N dot -A ) / ||A||
and, as you already have stated,
C := A - B

If e.g. the object run perpendicular to the wall (and you use unit normals for simplicity), then
N dot -A = ||A||
and
B = A
and
C = 0
what is correct.

EDIT: Sorry, the first posted version has had A and C confused.

##### Share on other sites
But I don't know C, I only know A and the wall W and want to know B (the force the wall gives in response to A) so that I can calculate C = A + B. (I want to calculate it that way, because that math also works when the object is only touching the end (corner) of the wall in which case it slides in a direction not parallel to the wall.)

##### Share on other sites
Yes, I have confused A and C; sorry for that. Is already corrected in the post above.

##### Share on other sites
Appendix: The object touches the wall in a single point. Furthurmore the wall has a single normal only if not doing a more elaborate stuff. If you want the object "go around the corner" of the wall, it may be necessary to compute the normal on the fly, e.g. as the unit vector pointing from the contact point to the center of the circle. So the normal will "wrap around" the corner of the wall.

##### Share on other sites
Yes, I have already worked that out. In my case N is the vector from the nearest point on the wall to the center of the object and B = A * (N dot -A) / ||A|| and then C = A - B, did I understand that right?

##### Share on other sites
I think that is right as long as your N is of unit length. (If not, then there is an additional dependence of the length of N!)

##### Share on other sites
Quote:
 Original post by CodeImpYes, I have already worked that out. In my case N is the vector from the nearest point on the wall to the center of the object and B = A * (N dot -A) / ||A|| and then C = A - B, did I understand that right?

You meant: B = N * (N.A)

##### Share on other sites
Yes ofcourse, N must be normalized.

ToohrVyk: B = N * (N.A) is the same as B = A * (N . -A) / ||A|| ?

##### Share on other sites
Quote:
 Original post by ToohrVykYou meant: B = N * (N.A)

Ahh, yes. Damned. Thx ToohrVyk.

N * (N dot A)
will shift the object back against N, while
A * (N dot -A) / ||A||
will shift it back from where it has come. The latter formula is typical for "non sliding" collision correction!

1. 1
Rutin
47
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632994
• Total Posts
3009766
• ### Who's Online (See full list)

There are no registered users currently online

×