我想在Java处理中以圆形运动移动一个正方形
这是一个学校项目,因此我不能使用很多诸如翻译或旋转之类的功能。我必须使用基本三角学来做到这一点。因此,我制作了一个正方形,我需要它以360度的圆形运动移动,其点恒定且不动。
float rotX,rotY;
size(500,500);
fill(#B71143);
int rectX=width/4;
int rectY=height/10;
int rectSize=30;
angle=angle+0.1;
//rotX=rectX*cos(angle)-rectY*sin(angle);
//rotY=rectX*cos(angle)+rectY*sin(angle);
square(rotX,rotY,rectSize);
This is a school project so i cannot use a lot of functions like translate or rotate. I have to use basic trigonometry to do this. So I have made a square and I need it to move in a circular motion 360 degrees with one of it's point constant and not moving.
float rotX,rotY;
size(500,500);
fill(#B71143);
int rectX=width/4;
int rectY=height/10;
int rectSize=30;
angle=angle+0.1;
//rotX=rectX*cos(angle)-rectY*sin(angle);
//rotY=rectX*cos(angle)+rectY*sin(angle);
square(rotX,rotY,rectSize);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至少就三角学部分而言,您是如此亲密。
在处理方面,您只缺少
setup()
anddraw()
它将绘制一个帧(一旦您取消注册rotx的作业,roty,roty < /code>和初始化
Angle
to 0)这是您的代码,上面的注释:
此外,如果要从中心绘制,则可以在渲染之前将宽度/高度的一半添加到方形坐标(相等的要翻译成中心),如果您想绘制一个圆而不是椭圆形,请使用两个RADII的大小(命名
rectx,retecty,retecty
):就我个人而言,我会有点简化代码(尽管您的作业要求可能会根据您的课程而有所不同)。
(如果您是沿着笛卡尔坐标的另一个极地转换公式的说明,则可以在这里查看我的较旧答案其中包括互动演示)
You are so close, at least in terms of the trigonometry part.
In terms of Processing you're only missing
setup()
anddraw()
which will draw a single frame (once you uncomment the assignments ofrotX, rotY
and initialiseangle
to 0)Here's your code with above notes applied:
Additionally, if you want to draw from the centre, you can add half the width/height to the square coordinates before rendering (equivalent to translating to centre), and if you want to draw a circle instead of an oval, use the same size for the two radii (named
rectX, rectY
):Personally I'd simplify the code a bit (though your assignment requirements might differ based on your curriculum).
(In case you're after another polar to cartesian coordinates conversion formula explanation you can check out my older answer here which includes an interactive demo)