2

For an elliptical billiard-table, how can a collision be detected and resolved between the boundary of this table and one billiard-ball?

1.) I want to see if the position, P(x,y), of the billiard-ball lies

  • inside
  • on
  • or outside the boundary of the ellipse. [update: part 1. is solved]

2.) If it lies on or outside the boundary, the new velocity has to be calculated (just flipping the velocity is not enough).

3.) If it lies outside, it has to be moved back to lie on the boundary first.

            ========
        ====      * ====
    ====                ====
    =                      =
    ====                ====
        ====        ====
            ========

Given is the position P(x,y) and the velocity V(x,y) of the billiard ball, plus the position of the center of the ellipse C(x_0,y_0) and both semi-axes a,b of the ellipse.

Ben
  • 15,938
  • 19
  • 92
  • 138
  • As much as I like solving problems like these, do you plan to code the solution? – Jacob Dec 07 '11 at 15:53
  • Also, do you just want to see if P(x,y) lies on the boundary of the ellipse? – Jacob Dec 07 '11 at 15:57
  • I edited my question to include more detail. I already did it for a circle, but I just can't seem to find the right start for the ellipse. – Ben Dec 07 '11 at 16:29

3 Answers3

2

Just use the equation of the ellipse like you used the equation for the circle:

((p.x-x0)/a)^2 + ((p.y-y0)/b)^2 = k

If k < 1 -> inside the ellipse

If k == 1 -> on the ellipse

If k > 1 -> outside the ellipse

Filip Navara
  • 4,818
  • 1
  • 26
  • 37
Jacob
  • 34,255
  • 14
  • 110
  • 165
  • Don't know why I didn't see that, thx! Now the less pleasant part: If the ball is outside the ellipse, it needs to be set back to the corresponding point on the boundary of the ellipse (i.e. ball managed to escape inbetween two frames). Furthermore, I just noticed that just flipping the velocity is not enough. Instead I need to calculate the new velocity? – Ben Dec 07 '11 at 20:08
  • 1
    Did you mean "If k==1 -> on the ellipse"? – Ryan Jun 26 '12 at 16:36
0

Since you are considering an elliptical (thus convex) board, I suppose you could use something based on GJK. You would get the point of contact and a surface normal during a collision, and the minimum distance between the objects and the associated witness points if there is no collision.

Collision detection with GJK is very fast and you could implement it for other shapes very easily (you only need to recode the support function). For an ellipse, I think the support function would be something like this (try to verify that) :

h=((x^2)/(a^4)+(y^2)/(b^4))^(-1/2)

Some links :

BenC
  • 8,729
  • 3
  • 49
  • 68
0

Some funny experiments with elliptic table. Delphi code (without error handling!).

//calculates next ball position in ellipse
//ellipse semiaxes A, B, A2 = A * A, B2 = B * B
//center CX, CY
//PX,PY - old position, VX,VY - velocity components
//V - scalar velocity V = Sqrt(VX * Vx + VY * VY)

procedure TForm1.Calc;
var
  t: Double;
  eqA, eqB, eqC, DD: Double;
  EX, EY, DX, DY, FX, FY: Double;
begin
  //new position
  NPX := PX + VX;
  NPY := PY + VY;

  //if new position is outside
  if (B2 * Sqr(NPX) + A2 * Sqr(NPY) >= A2 * B2) then begin

    //find intersection point of the ray in parametric form and ellipse
    eqA := B2 * VX * VX + A2 * VY * VY;
    eqB := 2 * (B2 * PX * VX + A2 * PY * VY);
    eqC := -A2 * B2 + B2 * PX * PX + A2 * PY * PY;
    DD := eqB * eqB - 4 * eqA * eqC;
    DD := Sqrt(DD);

    //we need only one bigger root
    t := 0.5 * (DD - eqB) / eqA;

    //intersection point
    EX := PX + t * VX;
    EY := PY + t * VY;

  //mark intersection position by little circle
    Canvas.Ellipse(Round(EX - 2 + CX), Round(EY - 2 + CY),
                   Round(EX + 3 + CX), Round(EY + 3 + CY));

    //ellipse normal direction
    DX := B2 * EX;
    DY := A2 * EY;
    DD := 1.0 / (DY * DY + DX * DX);

    //helper point, projection onto the normal
    FX := DD * (NPX * DX * DX + EX * DY * DY - DY * DX * EY + DX * DY * NPY);
    FY := DD * (-DX * DY * EX + DX * DX * EY + DX * NPX * DY + DY * DY * NPY);

    //mirrored point
    NPX := NPX + 2 * (EX - FX);
    NPY := NPY + 2 * (EY - FY);

    //new velocity components
    DD := V / Hypot(NPX - EX, NPY - EY);
    VX := (NPX - EX) * DD;
    VY := (NPY - EY) * DD;
  end;

  //new position
  PX := NPX;
  PY := NPY;

  //mark new position
  Canvas.Ellipse(Round(PX - 1 + CX), Round(PY - 1 + CY),
                 Round(PX + 1 + CX), Round(PY + 1 + CY));

end;

A = 125, B = 100 Start from ellipse center (left picture) and from the right focus point (right picture), ball reaches left focus, then returns to right focus

MBo
  • 77,366
  • 5
  • 53
  • 86