计算弧中心点,知道它的开始和结束度 [英] Calculate Arc Center Point, Knowing It's Start and End Degrees

查看:364
本文介绍了计算弧中心点,知道它的开始和结束度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是最快的说明答案是我试图找到白点的坐标。

The quickest description of this answer is that I am trying to find the coordinates of the white dot. The dark red is a drawn arc over a drawn circle (dark blue).

更长的解释:
我有一个扩展<$ c $的类c> View ,即在画布上绘制圆形(画布宽度和高度相等):

The longer explanation: I have a class that is extending View and that is drawing a circle on the canvas (the canvas has equal width and height):

canvas.drawArc(rectF, 0, 360, true, paint); // mOvals is a RectF object with 4 coordinates

然后我绘制一个宽度为N在这种情况下,我们说225)。电弧从-90度开始(因为画布中的0度表示3个时钟),而弧度表示N度(本例中为225度)。

Then I draw an arc that is N percent wide (let's say 225 in this case). The arc starts from -90 degrees (because 0 degrees in the canvas means 3'o clocks) and "strays" N degrees (225 in this example).

试图计算X / Y坐标或剩余弧的中心(未被红弧覆盖的区域,即N和360之间的区域)。

I am trying to calculate the X/Y coordinates or the center of the remaining arc (the area that is not covered by the red arc; that is between N and 360).

这是我绘制红色圆弧的方式:

Here's how I draw the red arc:

long arcEnd = (360 * fractionNumber) / totalNumber;
canvas.drawArc(rectF, -90, arcEnd, true, paint);


推荐答案

您正在寻找XY坐标(称为笛卡尔坐标),但这些都很难直接计算。诀窍是先经过极坐标。极坐标和笛卡尔坐标是表示同一事物的两种方式,即网格中的点,可以转换为彼此。

You're looking for the XY coordinates (called Cartesian coordinates), but these are difficult to calculate directly. The trick is to go through Polar coordinates first. Polar and Cartesian are two ways of expressing the same thing, namely a point in a grid and can be converted into eachother.

极坐标包括从中心的角度和距离点。您可以计算所需的角度,因为您知道需要覆盖的圆的百分比,您可以计算离中心的距离,因为您知道圆的半径。

Polar coordinates consist of angle and distance from the center point. You can calculate the desired angle because you know the percentage of the circle that you need to cover and you can calculate the distance from the center because you know the radius of the circle.

你的覆盖弧是225度,所以余数是135,一半是67.5度。因此,您要查找的点的角度为225 + 67.5 = 292.5度。该点的半径是圆的半径的一半,因此 canvasWidth / 4

Your covering arc is 225 degrees, so the remainder is 135 and half that is 67.5 degrees. The angle for the point you're looking for is therefore 225+67.5 = 292.5 degrees. The radius for that point is half the radius of the circle, so that's canvasWidth/4.

ve确定极坐标(292.5,canvasWidth / 4),使用转换函数。有一件事有点棘手: Math.cos(double) Math.sin(double)期望他们的参数成为弧度,而不是以度为单位。在进行转换之前,您将292.5 / 360表示为x /2π,这是通过将值乘以π/ 180,在这种情况下为5.1051。

Once you've determined the polar coordinate, (292.5, canvasWidth/4), you convert this to the XY coordinate using the conversion function. There's one thing that's a bit tricky: Math.cos(double) and Math.sin(double) expect their argument to be in radians, not in degrees. You express your 292.5/360 as x/2π before making the conversion, which you do by multiplying the value by π/180, giving 5.1051 in this case.

canvasWidth 是400:

double tdeg 292.5d; // Calculated from arc percentage 
int r =  100;      // Calculated from canvas width

double trad = tdeg * (Math.PI/180d); // = 5.1051

int x = (int) r * Math.cos(trad);
int y = (int) r * Math.sin(trad);

这篇关于计算弧中心点,知道它的开始和结束度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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