Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 根据雷达的角度中心X,Y所面对的角度计算新的X,Y位置_C#_Math - Fatal编程技术网

C# 根据雷达的角度中心X,Y所面对的角度计算新的X,Y位置

C# 根据雷达的角度中心X,Y所面对的角度计算新的X,Y位置,c#,math,C#,Math,我的游戏里有雷达。现在,雷达使用静态X,Y图形工作,不会根据你在我的游戏中面对的情况旋转 我希望雷达上的X,Y位置根据你面对的方向旋转。你面前的怪物总是出现在雷达的顶端 现在,雷达是静态的,你以北的怪物总是出现在雷达的北方 目前,我有这样的数学: int x = (int)(x * Math.Cos(Math.PI * angle / 180) + y * Math.Sin(Math.PI * angle / 180)); int y = (int)(y * Math.Cos(Math.PI *

我的游戏里有雷达。现在,雷达使用静态X,Y图形工作,不会根据你在我的游戏中面对的情况旋转

我希望雷达上的X,Y位置根据你面对的方向旋转。你面前的怪物总是出现在雷达的顶端

现在,雷达是静态的,你以北的怪物总是出现在雷达的北方

目前,我有这样的数学:

int x = (int)(x * Math.Cos(Math.PI * angle / 180) + y * Math.Sin(Math.PI * angle / 180));
int y = (int)(y * Math.Cos(Math.PI * angle / 180) - x * Math.Sin(Math.PI * angle / 180));
x2 = (int)(x * Math.Cos(Math.PI * angle / 180) - y * Math.Sin(Math.PI * angle / 180));
y2 = (int)(x * Math.Sin(Math.PI * angle / 180) + y * Math.Cos(Math.PI * angle / 180));
然后我把中心X和中心Y加在上面的整数上,但这张图很奇怪,似乎只从359度的角度工作。在计算之前,我尝试添加我的中心X和中心Y,但它总是关闭

我在网上找到的其他代码根据度数/角度进行区分

if (angle >= 0 && angle <= 180)
{
x = (int)(x * Math.Cos(Math.PI * angle / 180) - y * Math.Sin(Math.PI * angle / 180));
y = (int)(x * Math.Sin(Math.PI * angle / 180) + y * Math.Cos(Math.PI * angle / 180));
}
else
{
x = (int)(x * Math.Cos(Math.PI * angle / 180) - y * Math.Sin(Math.PI * angle / 180));
y = (int)(x * Math.Sin(Math.PI * angle / 180) + y * Math.Cos(Math.PI * angle / 180));
}

if(angle>=0&&angle显而易见的答案是使用旋转视角的相同旋转代码来旋转雷达坐标,但我猜你出于某种原因拒绝了

所有的示例代码都是错误的
x
正在被覆盖,然后用于查找
y
的新值。这是行不通的

基本旋转公式如下所示:

int x = (int)(x * Math.Cos(Math.PI * angle / 180) + y * Math.Sin(Math.PI * angle / 180));
int y = (int)(y * Math.Cos(Math.PI * angle / 180) - x * Math.Sin(Math.PI * angle / 180));
x2 = (int)(x * Math.Cos(Math.PI * angle / 180) - y * Math.Sin(Math.PI * angle / 180));
y2 = (int)(x * Math.Sin(Math.PI * angle / 180) + y * Math.Cos(Math.PI * angle / 180));
但如果付款人从0,0移走,您将需要

x2 = (int)((x - player_x) * Math.Cos(Math.PI * angle / 180) - (y - player_y) * Math.Sin(Math.PI * angle / 180));
y2 = (int)((x - player_x) * Math.Sin(Math.PI * angle / 180) + (y - player_y) * Math.Cos(Math.PI * angle / 180));
这将使雷达上的0,0以玩家为中心


D关于游戏如何测量角度,您可能需要交换Sin术语上的符号。

成功了,我只是删除了减去玩家位置并将其添加到公式后的操作。