Using dot product to calculate angle from three verts.
This commit is contained in:
parent
31609253f6
commit
3ee5f9b811
@ -22,7 +22,7 @@ public struct Angle : IAbsolute<Angle>, IAverage<Angle>, IClamp<Angle>, ICloneab
|
|||||||
}
|
}
|
||||||
public float Gradians
|
public float Gradians
|
||||||
{
|
{
|
||||||
get => p_deg * 1.11111111111f; // Reciprocal of 9/10 as a constant (10/9)
|
get => p_deg * 1.11111111111f;
|
||||||
set => p_deg = value * 0.9f;
|
set => p_deg = value * 0.9f;
|
||||||
}
|
}
|
||||||
public float Normalized
|
public float Normalized
|
||||||
@ -52,6 +52,15 @@ public struct Angle : IAbsolute<Angle>, IAverage<Angle>, IClamp<Angle>, ICloneab
|
|||||||
_ => throw new ArgumentException("Unknown type.", nameof(valueType)),
|
_ => throw new ArgumentException("Unknown type.", nameof(valueType)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static Angle FromVerts(Float3 endA, Float3 middleB, Float3 endC)
|
||||||
|
{
|
||||||
|
endA -= middleB;
|
||||||
|
endC -= middleB;
|
||||||
|
|
||||||
|
float dot = Float3.Dot(endA, endC);
|
||||||
|
return Mathf.ArcCos(dot * endA.InverseMagnitude * endC.InverseMagnitude);
|
||||||
|
}
|
||||||
|
|
||||||
public static Angle Absolute(Angle val) => new(Mathf.Absolute(val.p_deg));
|
public static Angle Absolute(Angle val) => new(Mathf.Absolute(val.p_deg));
|
||||||
public static Angle Average(params Angle[] vals) => new(Mathf.Average(SplitArray(Type.Degrees, vals)));
|
public static Angle Average(params Angle[] vals) => new(Mathf.Average(SplitArray(Type.Degrees, vals)));
|
||||||
public static Angle Ceiling(Angle val, Type type = Type.Degrees) =>
|
public static Angle Ceiling(Angle val, Type type = Type.Degrees) =>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user