**1**

###
#2
Members - Reputation: **620**

Posted 01 August 2012 - 08:17 AM

In 2D you'll get the normal by creating a vector from two points (a and b) on the surface. Then find the orthogonal vector and normalize it:

v = (b.x - a.x, b.y - a.y)

ortho = (-v.y, v.x)

n = normalize(ortho)

###
#3
Members - Reputation: **136**

Posted 03 August 2012 - 07:52 AM

If it is as a parametric surface, the normal at u,v is (basically) the cross product of the vectors: (u,v)->(u+delta,v) and (u,v)->(u,v+delta) where delta is the tolerance, normally based on the surface sample resolution.

But for starters, just use the polygon normal (normalized cross product of two edges of the nearest triangle).

**Edited by Catmull Dog, 03 August 2012 - 07:52 AM.**

###
#4
Members - Reputation: **107**

Posted 18 August 2012 - 08:59 PM

I am now calculating the normal to the surface by finding the velocity of the contact point and then normalizing that velocity. This does seem to give me the normal for that surface of contact. Is this right?

###
#5
Crossbones+ - Reputation: **2224**

Posted 19 August 2012 - 03:03 PM

I am now calculating the normal to the surface by finding the velocity of the contact point and then normalizing that velocity. This does seem to give me the normal for that surface of contact. Is this right?

No. The normal doesn't depend on the velocities etc of the colliding shapes, just their shapes.

Also - you're not looking for the "surface normal" - a property of just on of the contacting surfaces. You need to contact normal, which is a property of both surfaces.

You need to explain in more detail what you're trying to do. Giving a complete answer for the 3D case will be a waste of time and largely irrelevant if you're just concerning yourself with circles in 2D. However, the general result is: the contact normal you're looking for is the direction of the reaction forces in the case of zero friction (yes, that only helps when you know the answer... but by imagining what would happen in the zero friction case you might be able to work out what the normal must be).

For some contacts this is trivial - e.g. for a sphere/circle it will always be in the radial direction. For a contact with a face in 3D (whether a box or part of a triangle mesh etc) it will always be normal to the face. For an edge in 2D it will always be normal to the edge (you can think of a circle being made up of an infinite number of edges).

Basically in 2D, where you only have edges and corners, you need to consider only edge-corner contacts, which are trivial. You can ignore corner-corner contacts, and edge-edge contacts can be converted to two edge-corner contacts.

In 3D you have to deal with faces, edges and corners. Anything contacting a face results in the face's normal. If two edges contact take the cross product of the edges. Ignore corner-corner and corner-edge contacts.

If you already have the shapes penetrating, then a reasonable option is to take the direction that minimises the overlap/penetration distance.

**Edited by MrRowl, 19 August 2012 - 03:12 PM.**