按角度查找坐标
我正在 XNA 中开发绘制随机路径的应用程序。不幸的是,我对图表不太了解,所以我有点卡住了。我的应用程序需要执行以下操作:
- 从原点 (0,0) 选取一个随机角度,这很简单。
- 以上面找到的角度,相对于原点 16 像素(或我指定的任何距离)绘制一个圆。
(请原谅我糟糕的照片处理)
替代文字 http://www.refuctored.com/coor.png
(16,16) 处的第二个圆代表距原点 16 个像素的 45 度角。
我想要一种方法,在其中传递我的距离和角度,返回一个点到图形处。即
private Point GetCoordinate(float angle, int distance)
{
// Do something.
return new Point(x,y);
}
我知道这很简单,但同样,我对绘图非常不了解。有什么帮助吗?
谢谢, 乔治
I am developing in application in XNA which draws random paths. Unfortunately, I'm out of touch with graphing, so I'm a bit stuck. My application needs to do the following:
- Pick a random angle from my origin (0,0), which is simple.
- Draw a circle in relation to that origin, 16px away (or any distance I specify), at the angle found above.
(Excuse my horrible photoshoping)
alt text http://www.refuctored.com/coor.png
The second circle at (16,16) would represent a 45 degree angle 16 pixels away from my origin.
I would like to have a method in which I pass in my distance and angle that returns a point to graph at. i.e.
private Point GetCoordinate(float angle, int distance)
{
// Do something.
return new Point(x,y);
}
I know this is simple, but agian, I'm pretty out of touch with graphing. Any help?
Thanks,
George
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果角度以度为单位,则首先执行:
然后:
顺便说一句,(16, 16) 处的点距离原点不是 16 个像素,而是 sqrt(16^2 + 16^2) = sqrt(512) = 〜22.63 像素。
If the angle is in degrees, first do:
Then:
By the way, the point at (16, 16) is not 16 pixels away from the origin, but sqrt(16^2 + 16^2) = sqrt(512) =~ 22.63 pixels.
请注意,三角函数可能采用弧度。如果角度以度为单位,请除以 180/Pi。
Note that the trigonometric functions probably take radians. If your angle is in degrees, divide by 180/Pi.
一般来说:
其中 d 是距原点的距离,theta 是角度。
in general:
Where d is the distance from the origin and theta is the angle.
学习毕达哥拉斯定理。那么此帖子应该为您提供更具体的详细信息。
Learn the Pythagorean Theorem. Then this thread should have more specific details for you.