【问题标题】:Tangent to circle from external point.p从外部点与圆相切.p
【发布时间】:2014-01-13 08:50:43
【问题描述】:

我想画一个圆的两条切线,它的圆心(x1,y1)和半径(r)是已知的,切线穿过一个外部点(x0,y0),鉴于上述信息,我怎样才能找到这两条直线与圆的切点。提前致谢

附:我需要在 C++ 中执行此操作

【问题讨论】:

  • 对不起,我无法发布图片以便更好地解释场景..
  • 那么你知道几何,如何解决这个任务?事实上你知道斜边(你知道它的点)和cathetus(半径),这可以让你找到一个切点,然后你可以找到切线本身。如果你知道切线,你就可以画出来。
  • 欢迎来到stackoverflow!这个问题更像是一道数学题,有一个很棒的问答网站:math.stackexchange.com
  • 这个问题似乎跑题了

标签: c++ math opencv geometry


【解决方案1】:

在实践中计算切点的一些线索:

  1. 移动所有点以形成零中心圆 (P' = P0 - Center)
  2. 缩放以制作单位半径圆 (x^2+y^2=1, P = P'/R)
  3. 坐标的半径向量。切点的原点垂直于切线,因此它们的标量积为零:

    x*(X-x)+y*(Y-y)=0
    x*X + y*Y = x^2 +y^2 = 1    
    y = (1 - x*X)/Y
    
  4. 将y代入圆方程,求解该二次方程为x,然后求y

    x^2*(X^2+Y^2)+x*(-2X)+(1-Y^2)=0
    
  5. 恢复原始比例和偏移量

德尔福实现:

//finds tangent points to circle from external point (XX, YY)
//returns number of tangents (0, 1, 2)
function GetTangentPointsAtCircle(CenterX, CenterY, R, XX, YY: Double;
                                 var XT0, YT0, XT1, YT1: Double): Integer;
var
  nx, ny, xy, tx0, tx1, D: Double;
begin
  if R = 0 then //this behavior can be modified
    Exit(0);

  nx := (XX - CenterX) / R; //shift and scale
  ny := (YY - CenterY) / R;
  xy := nx * nx + ny * ny;

  if Math.SameValue(xy, 1.0) then begin //point lies at circumference, one tangent
    XT0 := XX;
    YT0 := YY;
    Exit(1);
  end;

  if xy < 1.0 then  //point lies inside the circle, no tangents
    Exit(0);

  //common case, two tangents
  Result := 2;
  D := ny * Sqrt(xy - 1);
  tx0 := (nx - D) / xy;
  tx1 := (nx + D) / xy;
  if ny <> 0 then begin //common case
    YT0 := CenterY + R * (1 - tx0 * nx) / ny;
    YT1 := CenterY + R * (1 - tx1 * nx) / ny;
  end else begin //point at the center horizontal, Y=0
    D := R * Sqrt(1 - tx0 * tx0);
    YT0 := CenterY + D;
    YT1 := CenterY - D;
  end;
  XT0 := CenterX + R * tx0; //restore scale and position
  XT1 := CenterX + R * tx1;
end;

【讨论】:

    【解决方案2】:

    虽然我同意这个问题离题并且应该关闭,但我还是会发布一个答案,因为它可能仍然有帮助。

    这是我要做的:我将计算圆的polar line,您可以通过将matrix representation of the circle 与点的homogeneous coordinates 相乘获得,即(x0, y0, 1)。生成的向量 (a,b,c) 描述了一条线 {(x,y)|ax+by+c=0},您可以将其与圆相交以找到切点。

    以上不仅适用于圆圈,也适用于任意平滑conics

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-30
      相关资源
      最近更新 更多