Collision Response - sphere/plane & finding plane normal.

In summary, the conversation discusses how to calculate the collision response for a sphere after colliding with a line (rail), including special cases for rails parallel or perpendicular to the X and Y axis. The conversation then explores how to handle collisions with "jaws" - rails at ±45° to the N, E, S, and W rails. The conversation also includes a discussion on calculating the plane normal and implementing the formula for collision response. Finally, the conversation suggests a simpler formula for 45°-collisions.
  • #1
gogreengo
12
0
Following on from my (still not quite solved) question here: Calculating event time using gsl_poly_solve_quadratic

I'm now looking to calculate the collision response (new linear velocity vector) for the sphere after a collision with a line (rail).

The current code I'm extending has two cases of rail collision implemented, that is for the N & S rails and the E & W rails such that the collision response is just a case of inverting one of either the X or the Y such that the pseudo code for new velocity for the N and S rails becomes (ignoring any damping coefficient):

Vector newV = Vector(oldV.x, -oldV.y);

and for the East and West rails:

Vector newV = Vector(-oldV.x, oldV.y);

I guess that these are obvious special cases for the rails that are either parallel or perpendicular to the X and Y axis.

In my question linked above, I'm extending this implementation to include 'jaws' - rails at the pockets that are at ±45° to the N,E,S &W rails. This has two parts, predicting the time of a collision (as discussed in the linked question) and then the handling of the collision event.


So my question is how to calculate the Collision Response for the South West pocket East Jaw as shown in the diagram below:

swpej_cr1.png


Let's assume that I want to detect and respond to a collision anywhere on that dashed red line (the infinite east jaw line). I've found various interpretations of an equation to use and in pseudo code is (EQ1):

reflected = 2 * plane.normal * (plane.normal * sphere.velocity)
sphere.velocity -= reflected


All looks simple except I'm not getting the expected results so I'm thinking I must be interpreting that equation incorrectly. Actually I'm pretty sure I'm not calculating the plane normal correctly.

  1. Is EQ1 shown above the correct way to determine the collision reaction I'm after?
  2. Am I correctly calculating the plane normal by doing the following:

    Taken from how-do-i-calculate-the-normal-vector-of-a-line-segment

    I'm trying to use, if dx=x2-x1 and dy=y2-y1, then the normals are (-dy, dx) and (dy, -dx).

    In this case given my definition of the line in the diagram above that will give:

    x1 = 0;
    y1 = -pocket_width;

    x2 = pocket_width;
    y2 = 0;

    dx=x2-x1;
    dx=pocket_width - 0;
    dx=pocket_width;

    dy=0 -(-pocket_width)
    dy=pocket_width

    ∴ the normals are (-pocket_width, pocket_width) and (pocket_width, -pocket_width)

    I assume these are both perpendicular to the line in each direction so one will be the one I want.

    Is this the correct way to calculate the plane.normal EQ1 above?
  3. Is this a correct implementation of EQ1?

    EQ1 = reflected = 2 * plane.normal * (plane.normal * sphere.velocity)
    sphere.velocity -= reflected


    Here I'm assuming that a vector3 * vector3 is in fact the cross product? I'm limited to implement this given the operators my Vector class provides and as such I get:

    double dx = Table::CORNER_POCKET_WIDTH;
    double dy = Table::CORNER_POCKET_WIDTH;

    Vector plane_normal = Vector(dy, -dx, 0);

    Vector ball_velocity = ball.getVelocity();

    Vector reflected = plane_normal.cross(plane_normal.cross(ball_velocity)) * 2;
    newVelocity = ball_velocity - reflected;


    Is that code equivalent to EQ1?
  4. Is there a better way to do what I want? Given that all the jaws will be ±45° to one of the rails is there a similar special case operation I can do like is being done for the N,E,S & W rails?


Sorry for so much information and so many questions..

Any ideas are greatly appreciated.

Cheers,
Lark
 
Last edited:
Physics news on Phys.org
  • #2
1.: It is
2.: Right. It does not matter which normal vector you use, they just differ by a sign and that sign cancels in the formula. You have to normalize that vector, however.

Here I'm assuming that a vector3 * vector3 is in fact the cross product?
Right

4.: For 45°-collisions, the final velocity has a nice, simple formula. Just find out what happens to a ball moving in x-direction, and a ball moving in (negative) y-direction. The general motion is just a sum of both motions, and the collision is linear (you can add them). That explanation is more complicated than the final formula now.
 
  • #3
@mfb, excellent, many thanks!
 

FAQ: Collision Response - sphere/plane & finding plane normal.

1. What is collision response?

Collision response is the process of determining how objects will react and interact with each other when they collide in a simulated environment. This involves calculating the forces and movements that will occur after the collision has taken place.

2. How do you handle collisions between a sphere and a plane?

To handle collisions between a sphere and a plane, you need to first calculate the distance between the center of the sphere and the plane. If this distance is less than the radius of the sphere, then a collision has occurred. Next, you need to find the point of contact between the sphere and the plane. This can be done by projecting the center of the sphere onto the plane. Finally, you can calculate the new velocity and direction of the sphere after the collision using the plane's normal vector.

3. What is the normal vector of a plane?

The normal vector of a plane is a vector that is perpendicular to the plane's surface. It is used to determine the orientation and direction of the plane. In the context of collision response, the normal vector is used to calculate the new velocity and direction of an object after a collision with the plane.

4. How do you find the normal vector of a plane?

To find the normal vector of a plane, you need to first determine three points that lie on the plane. These points can be used to create two vectors that form the plane's surface. Then, you can use the cross product of these two vectors to calculate the normal vector, which will be perpendicular to the plane's surface.

5. What are some common challenges in implementing collision response?

Some common challenges in implementing collision response include accurately detecting collisions between objects, handling collisions between complex or irregularly shaped objects, and ensuring that the response is physically realistic and does not result in objects passing through each other. Additionally, optimizing collision response for performance can also be a challenge, especially in complex simulations with many objects.

Back
Top