在给定中心点、半径和度数的圆上找到点 [英] Find the point on a circle with given center point, radius, and degree

查看:27
本文介绍了在给定中心点、半径和度数的圆上找到点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有 10 年没有做过这样的数学运算了……我正在编写一个 2D 游戏并让玩家四处移动.当我移动玩家时,我试图计算距离玩家位置 200 像素的圆上的点,给定 -360 到 360 之间的正或负角度(度).屏幕为 1280x720,0,0 为中心点的屏幕.玩家在整个笛卡尔坐标系中移动.我试图找到的点可能不在屏幕上.

It's been 10 years since I did any math like this... I am programming a game in 2D and moving a player around. As I move the player around I am trying to calculate the point on a circle 200 pixels away from the player position given a positive OR negative angle(degree) between -360 to 360. The screen is 1280x720 with 0,0 being the center point of the screen. The player moves around this entire Cartesian coordinate system. The point I am trying trying to find can be off screen.

我尝试了文章 找到具有半径的点上的公式和角度,但我不相信我理解角度"是什么,因为当我将角度作为 -360 到 360 传递给 Cos(angle) 或 Sin(angle) 时,我会得到奇怪的结果.

I tried the formulas on article Find the point with radius and angle but I don't believe I am understanding what "Angle" is because I am getting weird results when I pass Angle as -360 to 360 into a Cos(angle) or Sin(angle).

例如我有...

  • 1280x720 在笛卡尔平面上
  • 中心点(玩家的位置):
    • 让 x = 一个介于最小值 -640 到最大值 640 之间的数字
    • 让 y = 最小 -360 到最大 360 之间的数字

    在圆上返回 X 的公式是什么?

    在圆上返回 Y 的公式是什么?

    推荐答案

    链接中的简单方程给出了圆上点的 X 和 Y 坐标相对于圆心.

    The simple equations from your link give the X and Y coordinates of the point on the circle relative to the center of the circle.

    X = r * cosine(angle)  
    Y = r * sine(angle)
    

    这告诉您该点偏离圆心的距离.由于您有中心的坐标(Cx,Cy),只需添加计算出的偏移量.

    This tells you how far the point is offset from the center of the circle. Since you have the coordinates of the center (Cx, Cy), simply add the calculated offset.

    圆上点的坐标为:

    X = Cx + (r * cosine(angle))  
    Y = Cy + (r * sine(angle))
    

    这篇关于在给定中心点、半径和度数的圆上找到点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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