问题描述
如果你看这个图链接文本,我需要只知道直角三角形所有边的长度就可以找到角A.
If you would look at this diagram link text, I need to find angle A by only knowing the length of all sides of a right triangle.
我不知道三角函数,需要一些帮助.
I don't know trig and need some help.
推荐答案
您的帖子中实际上有 2 个问题.
There are actually 2 questions in your post.
如何使精灵指向鼠标.XNA C#:
How to make a sprite point at the mouse. XNA C#:
您必须计算精灵位置和鼠标位置之间的方向.这可以使用三角函数来完成.在这种情况下:Arctangens2
You will have to calculate the direction between the position of the sprite and the position of the mouse.This can be done using trigonometry functions. In this case: Arctangens2
那么让我们使用数学库:
So let's use the math library:
MouseState mouseState = Mouse.GetState();
Math.Atan2((double)mouseState.Y - sprite.Y, (double)mouseState.X - sprite.X); //this will return the angle(in radians) from sprite to mouse.
在您的三角学示例中,您将看到这些值实际上是:
In your trigonometry example you will see that those values actually are:
Math.Atan2(BC, AC);
或
Math.Atan2(Ydiff, Xdiff);
我希望这有帮助 =D
干杯,
TomHashNL
这篇关于如何使精灵指向鼠标.XNA C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!