# Box 2d Normal Vector for the surface of impact?

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

## Recommended Posts

As far as I can tell from online tutorials, the normal vector returned from a collision in box2d is the shortest direction for the colliding object to go to no longer penetrate the object it ran into. What I need is the normal vector of the surface it ran into, which is the direction the wall is pointing. For example, if I run into a vertical wall from the left, the normal vector I would expect would be <-1,0>. Is there a way to access this vector?

My ultimate goal is to reflect a raycast so I can map the path a projectile will take with no friction. Do raycasts allow reflections in box2d/farseer? I know many physics engines do, but I don't see that capability in Farseer.

Edited by WilkinzMicawber

##### Share on other sites

1. Yes, and generally that would be the normal vector for every physics engine. However, it may be inverted if the wall is not treated as the first object in a collision internally. This is solved by flipping the normal. IIRC in B2D it can be acessed by requesting a world manifold from a contact.

2. Yes, a world has an interface for ray casts and AABB queries, and the former returns the surface normal if the ray/segment hits your vertical wall.

Edited by Irlan Robson

##### Share on other sites

Ah, so the normal value in the return of a raycast is the surface normal, not the intersection normal? I had assumed that the normal returned was the collision normal for the ray.

Edited by WilkinzMicawber

##### Share on other sites

Yes.

For example, if a segment hits a face of a box, then the ray cast callback will be notified with the box, the face normal, and the intersection fraction which you can derive the intersection point from using linear interpolation:

p = (1.0 - fraction) * p1 + fraction * p2.

Edited by Irlan Robson

##### Share on other sites

Great! Thanks, Irlan. I greatly appreciate it. I was about to try and calculate the normal using multiple raycasts and trigonometry.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013739
×