找点圈在Android [英] Find point on Circle on Android

查看:157
本文介绍了找点圈在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切都显得那么朴实,直到我不得不实际编程。

我已经得到了

我上传的图像来解释它更好。

  • 我有一个圆圈,我知道

    • 在它的半径
    • 在中心点坐标
    • 在每个按钮的初始坐标(红圈)。

我希望能够,当我旋转灰色圆圈形象,10度,计算红色按钮的新坐标(X1Y1,X2Y2)。

这不应该是很难实现的人谁知道数学,但我没能找到一个合适的解决方案。我还搜查在这里,但没有找到一个有效的解决方案。任何帮助是极大的AP preciated。 谢谢

的工作方案,因为菲菲以下所述是:

- 首先照顾旋转角度,每个重绘简单的增加它

  =角度+ mainRotationAngle;

    浮动X =(浮点)(center.X + Math.cos(角度* Math.PI / 180F)*半径
    浮动Y =(浮点)(center.Y + Math.sin(角度* Math.PI / 180F)*半径

    button.setX(X);
    button.setY(Y);
 

解决方案

这是easyer如果你保持你的按钮初始的角度的,然后修改角度来产生旋转。所以在伪code:

  newAngle =角度+腐;
xbutton = center.x + COS(newAngle)*半径;
ybutton = center.y +罪(newAngle)*半径;
 

如果你真的只是按钮的坐标,您可以通过使用功能 ATAN2 ,在伪code并将其转换为角度:

  buttonAngle = ATAN2(button.y-center.y,button.x-center.x);
 

Everything seemed so plain and simple until I had to actually program it.

What I've got

I uploaded an image to explain it better.

  • I have a circle and I know

    • it's radius
    • center point coordinates
    • each button's initial coordinates (the red circles).

I want to be able, when I rotate the gray circle image, with 10 degrees, to calculate red buttons new coordinates (x1y1, x2y2).

This shouldn't be hard to achieve for someone who knows math, but I didn't manage to find a suitable solution. I've also searched around here and couldn't find a working solution. Any help is greatly appreciated. Thank you

The working solution, as Felice stated below is:

-first take care of rotation angle, on each redraw simply increment it

   angle = angle+mainRotationAngle;

    float x =  (float) (center.X + Math.cos(angle*Math.PI / 180F) * radius 
    float y =  (float) (center.Y + Math.sin(angle*Math.PI / 180F) * radius

    button.setX(x);
    button.setY(y);

解决方案

It is easyer if you keep with you the button initial angles, then modify the angle to produce the rotation. so in pseudocode:

newAngle = Angle+rot;
xbutton = center.x+cos(newAngle)*radius;
ybutton = center.y+sin(newAngle)*radius;

If you really just have the coordinates of the buttons, you can convert them to the angle by using the function atan2, in pseudocode:

buttonAngle = atan2(button.y-center.y,button.x-center.x);

这篇关于找点圈在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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