如何根据起始角度计算弧长? [英] How to calculate Arc length dependently of start angle?

查看:341
本文介绍了如何根据起始角度计算弧长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个道路编辑器,可以在其中将预定义的路段拖动到一起,并将它们组合到连接的道路上.这些线段之一是右曲线.

I am building a road editor where one can drag predefined road segments together and combine them to a connected road. One of those segments is a right curve.

该曲线绘制为SVG(使用D3弧路径功能),并具有两个手柄以直接在SVG内更改半径和长度(黑色小圆圈更改长度,黑色小方形更改半径).我在手柄上使用了d3拖动处理程序.

The curve is drawn as SVG (using D3 arc path function) and has two handles to change the radius and the length directly within the SVG (small black circle changes length and small black square changes the radius). I use a d3 drag handler on the handles.

要计算新的圆心角,请执行以下操作:

To calculate the new central angle I do as follows:

  1. 从圆弧的中心点获取YOffset
  2. 翻转YOffset(以匹配屏幕y和数学值)
  3. 使用毕达哥拉斯(x = Math.sqrt(r ^ 2-YOffset ^ 2))获得相应的x值
  4. 获取相应的中心角(Math.PI/2-Math.atan2(YOffset,x);

只有在圆弧从PI/2开始时才有效,如图所示.如果我添加具有任意起始角度的其他弧(请参见下图,红色弧),则我的解决方案将无法工作.

This will only work if the arc starts at PI/2 like in the figure. If I add further arcs with arbitrary start angles (see next figure, red arc), my solution wont work.

我正在寻找一种通用的解决方案,因此无论其起始角度如何,它都能适用于任何弧形.

I'm looking for a general solution so it will work for any arc regardless of its start angle.

推荐答案

对我来说,这似乎不是编程问题,而是数学问题.我的理解是:给定起点(x₁, y₁),终点pont (x₂, y₂)和半径r,角度α是多少?

To me it seems this is not much of a programming problem, but of math. What I understand is: given a start point (x₁, y₁), an end pont(x₂, y₂) and a radius r, what is the angle α?

您可以计算两点之间的距离d.它的长度的一半是直角三角形的远端,以r作为其假设. d/2r是近角的窦;将其加倍,您将在端点之间形成角度.

You can compute the distance d between the two points. Half its length is the far leg of a right triangle with r as its hypothenuse. d/2r is the sinus of the near angle; double that and you have the angle between the end points.

(而且,以弧度表示α的路径长度就是α * r.)

(And, having α expressed in radians, the path length is simply α * r.)

这篇关于如何根据起始角度计算弧长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆