Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.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
Java 如何根据角度和距离获取坐标系中点的坐标_Java_Math_Trigonometry - Fatal编程技术网

Java 如何根据角度和距离获取坐标系中点的坐标

Java 如何根据角度和距离获取坐标系中点的坐标,java,math,trigonometry,Java,Math,Trigonometry,当我只有原点坐标(x,y)和从原点到点的角度以及从原点到点的距离时,如何获得坐标系中点的坐标 px = x + r * cos(phi) py = y + r * sin(phi) 其中,[px py]是您要搜索的点,[x y]是“原点”,r是距离,phi是从原点到目标的角度 编辑:巴特·基尔斯(Bart Kiers)发布的这个链接可以提供一些背景信息。您使用的链接如下: pointX = x + distance * Math.cos(angle) pointY = y + distance

当我只有原点坐标(x,y)和从原点到点的角度以及从原点到点的距离时,如何获得坐标系中点的坐标

px = x + r * cos(phi)
py = y + r * sin(phi)
其中,
[px py]
是您要搜索的点,
[x y]
是“原点”,
r
是距离,
phi
是从原点到目标的角度

编辑:巴特·基尔斯(Bart Kiers)发布的这个链接可以提供一些背景信息。

您使用的链接如下:

pointX = x + distance * Math.cos(angle)
pointY = y + distance * Math.sin(angle)


关于弧度/度的注意事项:
Math.cos
Math.sin
假设参数在弧度中给出。如果角度以度为单位,则可以使用
Math.cos(
例如。

如果d是距离,A是角度,则点的坐标将为


(x+d*Cos(A),y+d*Sin(A))

如果
r
是到原点的距离,
A
是x轴和点之间的角度(弧度),则可以通过极坐标的转换轻松计算坐标:

x = r*cos(a)
y = r*sin(a)
(假设原点位于
(0,0)
,否则应将位移添加到最终结果中)

通过计算向量的模(因为距离+角度构成向量)和反正切,可以使用
atan2
函数计算得出相反的结果

r = sqrt(x*2+y*2)
a = atan2(y,x)

简短回答

// math equations    
pointX = distance * cos(angle) + x  
pointY = distance * sin(angle) + y

// java code [angle in radian]
double pointX = distance * Math.cos(Math.toRadians(angle)) + x;  
double pointY = distance * Math.sin(Math.toRadians(angle)) + y;
详细答案

// math equations    
pointX = distance * cos(angle) + x  
pointY = distance * sin(angle) + y

// java code [angle in radian]
double pointX = distance * Math.cos(Math.toRadians(angle)) + x;  
double pointY = distance * Math.sin(Math.toRadians(angle)) + y;
如下图所示

// finding pointX let's start by 
cos(angle) = (pointX - x) / distance
distance * cos(angle) =  (pointX - x)
(pointX - x) = distance * cos(angle)
pointX = distance * cos(angle) + x

// finding pointY let's start by 
sin(angle) = (pointY - y) / distance
distance * sin(angle) =  (pointY - y)
(pointY - y) = distance * sin(angle)
pointY = distance * sin(angle) + y

听起来更像是一个数学(特别是代数)问题,而不是一个计算问题。你知道计算新点所需的公式吗?或取决于坐标系的类型,但大多数情况下使用称为sin(),cos()的简单三角函数。这是错误的,因为它没有考虑到该点偏移了其他任意点(x,y)。@kigurai;谢谢你指点。编辑代码。当我打字的时候,它就在我的脑海里,我不知道我怎么会错过它。。。无论如何,再次感谢…+1:因为它实际上使用了Java函数,而我的答案并没有:)如何为3D系统修改它?