【问题标题】:How to calculate the Cordinates of end point in an Arc if center and starting coordinates are Known along with sweeping angle in Android..?如果中心和起始坐标以及Android中的扫掠角已知,如何计算弧中端点的坐标..?
【发布时间】:2012-10-25 06:29:33
【问题描述】:

我正在绘制一个饼图,其中我已经绘制了已知扫角的弧。现在我想在每个弧的中心显示标签,或者说从每个弧的中心画一条线。

鉴于我知道中心坐标、起始坐标、扫角和半径,我想计算结束坐标。

我也尝试过绘制一个匹配所有坐标的三角形并使用距离公式,但我不知道如何在 java 中求解方程。

请给我一个合适的解决方案。

【问题讨论】:

    标签: java android math geometry pie-chart


    【解决方案1】:

    在向量中工作。让A 成为从圆心到圆弧起点的向量。计算方式

    A = start_point - centre
    

    theta 为扫角(以弧度为单位)。使用旋转矩阵围绕圆心旋转圆弧起点。 http://en.wikipedia.org/wiki/Rotation_matrix

    明确地说,

    newpoint_x = cos(theta)*A_x + sin(theta)*A_y
    newpoint_y = -sin(theta)*A_x + cos(theta)*A_y
    

    其中A_xA 的x 分量(A_y 也是如此)。那么

    newpoint = centre + (newpoint_x,newpoint_y)
    

    是你想要的点。可能是该点以错误的方式旋转(逆时针),如果是这样,请使用

    theta = -theta
    

    相反。这应该适合你。

    如果要评估弧的中点,只需使用

    theta = theta / 2
    

    【讨论】:

    • 感谢您的回答。我几乎明白了,但不知道如何在 java 中使用向量(数学)..
    【解决方案2】:
    StartAngle = atan2(StartY-CenterY, StartX - CenterX) 
    EndX = CenterX + Radius * Cos(StartAngle + SweepAngle)
    EndY = CenterY + Radius * Sin(StartAngle + SweepAngle)
    

    另一种方式: 制作

    的矩阵乘积
    shift by (Center - Start)
    rotation by SweepAngle
    back shift
    

    并将此矩阵应用于起点(矩阵和向量相乘)

    【讨论】:

    • 感谢您的支持..上述方法计算终点当 SweepAngle
    猜你喜欢
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    • 1970-01-01
    • 1970-01-01
    • 2015-06-18
    相关资源
    最近更新 更多