Using dot product to calculate angle from three verts.

This commit is contained in:
That_One_Nerd 2023-07-26 09:44:32 -04:00
parent 31609253f6
commit 3ee5f9b811

View File

@ -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) =>