在 Android 上查找圆上的点
一切看起来都那么简单明了,直到我必须真正对其进行编程。
我得到的
我上传了一张图片来更好地解释它。
我有一个圈子,我知道
- 半径
- 中心点坐标
- 每个按钮的初始坐标(红色圆圈)。
我希望能够在将灰色圆形图像旋转 10 度时计算红色按钮的新坐标 (x1y1, x2y2)。
对于懂数学的人来说这应该不难实现,但我没有找到合适的解决方案。我也在这里搜索过,但找不到可行的解决方案。非常感谢任何帮助。 谢谢
正如 Felice 下面所述,工作解决方案是:
-首先处理每个旋转角度重绘只需增加它
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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您保留按钮初始角度,然后修改角度以产生旋转,则会更容易。因此,在伪代码中:
如果您确实只有按钮的坐标,则可以使用函数
atan2
将它们转换为角度,在伪代码中:It is easyer if you keep with you the button initial angles, then modify the angle to produce the rotation. so in pseudocode:
If you really just have the coordinates of the buttons, you can convert them to the angle by using the function
atan2
, in pseudocode:x1 = x + r sin 10
y1 = y + r cos 10
x2 = x - r sin 10
y2 = y - r cos 10
x1 = x + r sin 10
y1 = y + r cos 10
x2 = x - r sin 10
y2 = y - r cos 10