如何以度为单位计算角度? [英] How do I calculate the angle in degrees?

查看:131
本文介绍了如何以度为单位计算角度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Codeproject,



假设我有两个向量点。



< pre lang =c#> / * 用于开始角度计算的向量。 * /
Vector2 PointStart = new Vector2(Room.Width / 2 , Room.Height / 2 );
Vector2 PointMouse = new Vector2(Mouse.X,Mouse.Y);

/ * 设置角度。 * /
Angle = Angle.From(PointStart,PointMouse);





我尝试过:

  / *  获取void之间的角度。 * /  
/// < 摘要 >
/// 检索两点(矢量)之间的角度。
/// < / summary >
/// < param < span class =code-summarycomment> name =i > 首发vector。< / param >
/// < param name =j < span class =code-summarycomment>> 指向另一个向量的点(12点)< / param >
/// < 返回 > < / returns >
public float AngleToMouse(Vector2 Mouse)
{
/ * Delta * /
DeltaPoint = new Vector2( ( this .PositionX + Mouse.X) - this .PositionX,(这个 .PositionY + Mous e.Y) - this .PositionY);

/ * 返回* /
return float )(Math.Atan2(DeltaPoint.Y,DeltaPoint.X)* 180 / Math.PI);
}





但结果是:



[ ^ ]

请帮助!



如何进行上述操作?



- Riberto

解决方案

请参阅:

计算学位失败! [ ^ ]。



请不要再发帖了。



-SA


我会使用标量乘积公式,即 v1。 v2 = | v1 | | V2 | cos(phi)

因此 phi = arccos(x1 * x2 + y1 * y2 / sqrt(x1 * x1 + y1 * y1)/ sqrt(x2 * x2 + y2 * y2))





  public   double  Angle(Vector2 v1,Vector2 v2)
{
double v1m = Math.Sqrt(v1.X * v1.X + v1.Y * v1.Y);
double v2m = Math.Sqrt(v2.X * v2.X + v2.Y * v2.Y);
double angle = 180 * Math.PI * Math.Acos((v1.X * v2.X + v1.Y * v2.Y)/ v1m / v2m);
返回角度;
}


Hello Codeproject,

Let''s assume I have two vector points.

/* Vectors to begin angle calculation. */
Vector2 PointStart = new Vector2(Room.Width / 2, Room.Height / 2);
Vector2 PointMouse = new Vector2(Mouse.X, Mouse.Y);

/* Set the angle. */
Angle = Angle.From(PointStart, PointMouse);



I have however attempted this:

/* Get Angle between void. */
/// <summary>
/// Retrieves the angle between two points(Vectors).
/// </summary>
/// <param name="i">The starting vector.</param>
/// <param name="j">The point to the other vector(12 o' clock)</param>
/// <returns></returns>
public float AngleToMouse(Vector2 Mouse)
{
    /* Delta */
    DeltaPoint = new Vector2((this.PositionX + Mouse.X) - this.PositionX, (this.PositionY + Mouse.Y) - this.PositionY);

    /* Return */
    return (float)(Math.Atan2(DeltaPoint.Y, DeltaPoint.X) * 180 / Math.PI);
}



But the result was:

[^]
Help please!

How would I do the above?

- Riberto

解决方案

Please see:
Calculating degrees fails![^].

Please don''t re-post anymore.

—SA


I would use the scalar product formula, namely v1 . v2 = |v1| |v2| cos(phi).
Hence phi = arccos( x1*x2+y1*y2/sqrt(x1*x1+y1*y1)/sqrt(x2*x2+y2*y2)).


public double Angle(Vector2 v1, Vector2 v2)
{
   double v1m = Math.Sqrt(v1.X*v1.X+v1.Y*v1.Y);
   double v2m = Math.Sqrt(v2.X*v2.X+v2.Y*v2.Y);
   double angle = 180 * Math.PI * Math.Acos(( v1.X*v2.X+v1.Y*v2.Y ) / v1m / v2m);
   return angle;
}


这篇关于如何以度为单位计算角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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