如何在游戏中找到坐标(三角问题)? [英] How do I find a coordinate in my game (trigonometry question)?

查看:144
本文介绍了如何在游戏中找到坐标(三角问题)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想找到游戏中某个点的X和Y坐标。



我有一个起点(origo),我有物体的长度(以像素为单位),我有物体的旋转。



换句话说:如果物体躺在地上,X点将是原点+物体的长度,Y点与原点相同。



但如果对象倾斜说55度怎么办?我正试图找到这个物体指向的最近的X和Y位置。



我问的原因是我正在用大炮创造一个游戏应该在这个位置射击,而不是从物体中间射击。





感谢您的任何建议!



Petter



我尝试过:



我看过窦,cosinus和正切数学公式,但不认为它们是适用的,无论如何我不知道怎么用C#写这个。

解决方案

我自己想出了解决方案。当我绘制直线,角度和坐标系时,我看到与物体长度相反,相应的角度总是90度。



因此,我有90度角,已知角度和两条线的长度之一。

这意味着我可以使用正弦法



我希望这可以帮助处于相同情况的任何人。



Petter

Hi,

I am trying to find the X and Y coordinates of a certain point in my game.

I have a starting point ("origo"), I have the length of my object (in pixels), and I have the rotation of the object.

In other words: if the object would be lying on the ground the X point would be origo + the length of the object, and the Y point would be the same as origo.

But what if the object is tilted say 55 degrees? I'm trying to locate the nearest X and Y position of where this object points then.

The reason why I ask is that I am creating a game with a cannon and shots that should be fired at this position, not from the middle of the object.


Thanks for any suggestions!

Petter

What I have tried:

I have looked at the sinus, cosinus, and tangent math formulas, but don't think they are applicable, and in any case I don't know how to write this in C#.

解决方案

I came up with the solution myself. When I drew the line, angle, and the coordiante system I saw that opposite the length of the object, the corresponding angle is always 90 degrees.

Thus, I have a 90 degree angle, a known angle, and one of the two lines' length.
This means that I can use the law of sines.

I hope this helps anyone in the same situation.

Petter


这篇关于如何在游戏中找到坐标(三角问题)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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