0

I am trying to implement a collision system for my three js racing game. I am following this guide to implement the system which calculates the final linear and angular velocities following a collision between two cars.

https://www.myphysicslab.com/engine2D/collision-en.html#resting_contact

However I have troubling when it comes to finding the correct direction for the normal. According to the link: Let the vector n be normal (perpendicular) to the edge of body B that is being impacted, and pointing outward from body B. I am using the following method for finding this normal.

How do I calculate the normal vector of a line segment?

Finding the numerical value of the normal is easy but I have trouble making my program use the correct direction. For instance i want the blue normal and not the red one.

Here is a picture that explains what i mean more clearly I hope:

img

Spektre
  • 49,595
  • 11
  • 110
  • 380
jpc99
  • 27
  • 1
  • 5
  • Welcome to Stack Overflow. Questions may include links, but ought not to *rely* on them. If something is necessary to the question, put it in the question. If you tell us about the variables that define these objects and their collision, maybe we can tell you how to calculate the normal. – Beta Dec 03 '17 at 02:55
  • 1
    Didn't check the links but from the picture it looks as if you want the normal whose dot product with `rap` is greater than zero. – Nico Schertler Dec 03 '17 at 08:48
  • Are the vectors `r_ap` and `r_bp` in 2D or 3D? How does the orientation of the normal vector impact your calculations? What is your goal? – coproc Dec 03 '17 at 10:52

1 Answers1

0

No formula can guess what side of the surface you are interested in, so it is up to you to provide this hint.

You can select the right orientation that by using one of Rap x Rbp or Rbp x Rap, but it is up to you to choose depending on the orientation conventions used in your model. (With the little information provided, I can't tell you more.)