2

对于一个椭圆台球台,如何检测和解决该台球台边界与一个台球之间的碰撞?

1.) 我想看看台球的位置 P(x,y) 是否位于

  • 里面
  • 或在椭圆的边界之外。[更新:第 1 部分。已解决]

2.)如果它位于边界或边界,则必须计算新的速度(仅翻转速度是不够的)。

3.) 如果它在外面,它必须先移回边界上。

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

给定台球的位置 P(x,y) 和速度 V(x,y),加上椭圆中心的位置 C(x_0,y_0) 和椭圆的两个半轴 a,b .

4

3 回答 3

2

只需使用椭圆方程,就像使用圆方程一样:

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

如果 k < 1 -> 在椭圆内

如果 k == 1 -> 在椭圆上

如果 k > 1 -> 在椭圆之外

于 2011-12-07T18:57:52.347 回答
0

一些有趣的椭圆表实验。Delphi 代码(没有错误处理!)。

//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 从椭圆中心(左图)和右焦点(右图)开始,球到达左焦点,然后返回右焦点

于 2011-12-08T11:40:40.730 回答
0

由于您正在考虑使用椭圆(因此是凸面)板,我想您可以使用基于GJK的东西。您将在碰撞期间获得接触点和曲面法线,以及在没有碰撞时对象与关联见证点之间的最小距离。

GJK 的碰撞检测非常快,您可以很容易地为其他形状实现它(您只需要重新编码支持功能)。对于椭圆,我认为支持函数是这样的(尝试验证):

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

一些链接:

于 2011-12-07T17:06:39.943 回答