Sign in to follow this  

Sliding vector from velocity vs a wall

This topic is 4391 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

Or whatever you want to call it... I'll make my case clear with this drawing: Image Hosted by ImageShack.us 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by CodeImp
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?


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

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
You 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!

Share this post


Link to post
Share on other sites
ok I understand that was a correction :)
To summerize it all;

B = N * (N . A) and C = A - B
Where A is the object velocity vector,
N is the normalized vector from nearest point on the wall to the object,
B is the force coming from the wall in response to A,
and C is the resulting slide vector that the object will follow.

Share this post


Link to post
Share on other sites
[edit: oops beaten ...]

I'll just clarify something here that might make it easier to understand. The projection of a vector u onto another vector v is given by

projv(u) = (u.v)/(v.v) * v

where . represents dot product. In your case B is the projection of A onto the wall normal, which I'll call N. If N is a unit vector then the above simplifies to

B = projN(A) = A.N * N

since N.N = |N|2 = 1

To get the sliding vector C, as you have said simply compute C = A-B.

Share this post


Link to post
Share on other sites
At the moment _I_ think it is correct ;-)

N dot A should be negative, so that B points against the direction of N. In
N * (N dot A)
only a single vector of non unit length is contained, so the length should be projected correctly. Yes, I think now it is ok.

Share this post


Link to post
Share on other sites

This topic is 4391 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this