本文整理汇总了C#中Vector2F.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2F.Normalize方法的具体用法?C# Vector2F.Normalize怎么用?C# Vector2F.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector2F
的用法示例。
在下文中一共展示了Vector2F.Normalize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Normalize
public void Normalize()
{
Vector2F v, n1, n2;
float magnitude;
v = new Vector2F(3.0f, 4.0f);
n1 = v.Normalize();
n2 = v.Normalize(out magnitude);
Assert.AreEqual(1.0f, n1.Magnitude, 1e-14);
Assert.AreEqual(1.0f, n2.Magnitude, 1e-14);
Assert.AreEqual(5.0f, magnitude, 1e-14);
}
示例2: NormalizeZeroVector
public void NormalizeZeroVector()
{
Vector2F v = new Vector2F(0.0f, 0.0f);
Vector2F n1 = v.Normalize();
Assert.IsNaN(n1.X);
Assert.IsNaN(n1.Y);
Assert.IsTrue(n1.IsUndefined);
float magnitude;
Vector2F n2 = v.Normalize(out magnitude);
Assert.IsNaN(n2.X);
Assert.IsNaN(n2.Y);
Assert.IsTrue(n2.IsUndefined);
Assert.AreEqual(0.0f, magnitude);
}
示例3: DrawArrow
private void DrawArrow(PaintEventArgs e, Pen pen, float x1, float y1, float x2, float y2, float fPtrSize, bool bStart, bool bEnd)
{
e.Graphics.DrawLine(pen, x1, y1, x2, y2);
Vector2F dir = new Vector2F(x2 - x1, y2 - y1);
dir.Normalize();
dir *= fPtrSize;
if (bStart)
{
e.Graphics.DrawLine(pen, x1, y1, x1 + dir.X + dir.Y, y1 + dir.Y - dir.X);
e.Graphics.DrawLine(pen, x1, y1, x1 + dir.X - dir.Y, y1 + dir.Y + dir.X);
}
if (bEnd)
{
e.Graphics.DrawLine(pen, x2, y2, x2 - dir.X + dir.Y, y2 - dir.Y - dir.X);
e.Graphics.DrawLine(pen, x2, y2, x2 - dir.X - dir.Y, y2 - dir.Y + dir.X);
}
}
示例4: Normalize
public void Normalize()
{
Vector2F v = new Vector2F(3.0f, -1.0f);
v.Normalize();
Assert.IsTrue(v.IsNumericallyNormalized);
}
示例5: FromVector
/// <summary>
/// Returns the angle between the specified vector and the x-axis.
/// Example: FromVector(0.5, 0.5) will return DegreesToRadians(45).
/// </summary>
/// <remarks>
/// See http://stackoverflow.com/questions/6247153/angle-from-2d-unit-vector for details.
/// </remarks>
/// <param name="v">Vector to get the angle of.</param>
/// <returns>Angle between the specified vector and the x-axis.</returns>
public static float FromVector(Vector2F v)
{
var normalized = v.Normalize();
return Atan2(normalized.Y, normalized.X);
}