本文介绍了几何弧算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了所有互联网,但没有找到任何伪代码可以解决此问题,
我想使用5个参数在A和B两点之间找到一条弧:

I searched all internet and didn't find any pseudo code that solved this problem,I want to find an Arc between two points, A and B, using 5 arguments:


  1. 起点

  2. 终点

  3. 半径(不知道是否需要这样做) )

  4. 角度

  5. 质量

  1. Start Point
  2. End Point
  3. Radius (Don't know if this is needed)
  4. Angle
  5. Quality

示例:

起点=左侧的绿点是在参数上设置的起点

StartPoint = The green point on the left is the Start Point set on the arguments

终点=绿点右边是在参数上设置的终点

EndPoint = The green point on the right is the End Point set on the arguments

角度=圆弧(半圆)的角度

Angle = Angle of the Arc(Semi Circle)

质量=要创建多少个红色圆圈

Quality = How many red circles to create

我想使用伪代码来解决此问题

I would like to have a pseudo code to solve this problem

谢谢预先:D

推荐答案

让起点为P0,终点为P1,角度为Fi。 不需要R

Let start point is P0, end point P1, angle Fi. R is not needed

首先找到弧中心。获取P0-P1段的中间位置。

At first find arc center. Get middle of P0-P1 segment.

 M = (P0 + P1) / 2 
 // M.x =  (P0.x + P1.x) / 2 , same for y

和方向矢量相同

 D = (P1 - P0) / 2

获取D的长度

 lenD = Math.Hypot(D.x, D.y)  //Vector.Length, sqrt of sum of squares

获取单位向量

 uD = D / lenD

获取(左)垂直向量

 (P.x, P.y) = (-uD.y, ud.x)

现在的圆心

 if F = Pi then
     C.x = M.x
     C.y = M.y
 else
     C.x = M.x + P.x * Len / Tan(Fi/2)
     C.y = M.y + P.y * Len / Tan(Fi/2)

从中心到起点的向量:

CP0.x = P0.x - C.x
CP0.y = P0.y - C.y

然后可以使用向量CP0绕中心点旋转计算圆弧上N个中间点的坐标

Then you can calculate coordinates of N intermediate points at the arc using rotation of vector CP0 around center point

 an = i * Fi / (NSeg + 1);
 X[i] = C.x + CP0.x * Cos(an) - CP0.y * Sin(an)
 Y[i] = C.y + CP0.x * Sin(an) + CP0.y * Cos(an)

工作的Delphi代码

Working Delphi code

procedure ArcByStartEndAngle(P0, P1: TPoint; Angle: Double; NSeg: Integer);
var
  i: Integer;
  len, dx, dy, mx, my, px, py, t, cx, cy, p0x, p0y, an: Double;
  xx, yy: Integer;
begin
  mx := (P0.x + P1.x) / 2;
  my := (P0.y + P1.y) / 2;

  dx := (P1.x - P0.x) / 2;
  dy := (P1.y - P0.y) / 2;

  len := Math.Hypot(dx, dy);

  px := -dy / len;
  py := dx / len;

  if Angle = Pi then
    t := 0
  else
    t := len / Math.Tan(Angle / 2);

  cx := mx + px * t;
  cy := my + py * t;

  p0x := P0.x - cx;
  p0y := P0.y - cy;

  for i := 0 to NSeg + 1 do begin

   an := i * Angle / (NSeg + 1);
   xx := Round(cx + p0x * Cos(an) - p0y * Sin(an));
   yy := Round(cy + p0x * Sin(an) + p0y * Cos(an));

   Canvas.Ellipse(xx - 3, yy - 3, xx + 4, yy + 4);
  end;
end;

的结果(Point(100,0),Point(0,100 ),Pi / 2、8 (图片的Y轴向下)

这篇关于几何弧算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:47