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

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

问题描述

这个答案的最快的描述是,我试图找到白点的坐标。暗红色,就是拉弧通过绘制圆(深蓝色)。

在较长的解释: 我有一个是延长查看那就是画一个圆圈在画布上一个类(画布有平等的宽度和高度):

  canvas.drawArc(rectF,0,360,真实,油漆); // mOvals是4坐标RectF对象
 

然后我划出一道弧线的是N%的广(比方说,在这种情况下,225)。电弧开始从-90度(因为在画布0度装置3'o时钟)和流浪N度(在本例中225)。

我试图计算/ Y坐标的X或其余圆弧的中心(即不包括的红色弧面积,即N和360之间)的

我是canvasWidth / 2的圆的半径,如果这是有一定的帮助。

下面就是我画的红色弧线:

 长arcEnd =(360 * fractionNumber)/ totalNumber;
canvas.drawArc(rectF,-90,arcEnd,真实,油漆);
 

解决方案

(原来的答复更新。这可能有点太详细了,但我希望它能帮助。)

您正在寻找的XY坐标(称为直角坐标),但这些都难以直接计算。诀窍是要首先通过极坐标。极性和笛卡尔是前$ P $两种方式pssing同样的事情,即一个点的网格和可转换成海誓山盟

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

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

一旦你已经确定的极坐标,(292.5,canvasWidth / 4),你将它转换为XY坐标使用<一个href="http://en.wikipedia.org/wiki/Polar_coordinates#Converting_between_polar_and_Cartesian_coordinates"相对=nofollow>转换功能。有一件事,这是一个有点棘手: Math.cos(双) Math.sin(双)期待他们的说法要在弧度,而不是在度。你离preSS的292.5 / 360作为使转换,这你乘以值π/ 180,在这种情况下,给予5.1051之前的x /2π

假设 canvasWidth 400

 双tdeg 292.5d; //从弧百分比来计算
INT R = 100; //从画布宽度计算

双繁体= tdeg *(Math.PI / 180D); // = 5.1051

INT X =(int)的R * Math.cos(繁体);
INT Y =(int)的R * Math.sin(繁体);
 

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).

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

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).

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).

I have the radius of the circle which is canvasWidth/2 if that is of some help.

Here's how I draw the red arc:

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

解决方案

(Original answer updated. It may be a bit too verbose now, but I hope it helps.)

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.

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.

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.

Assuming that canvasWidth is 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天全站免登陆