Skip to content

Commit

Permalink
Make use of Angle.SinCo
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed Oct 20, 2023
1 parent 12f1493 commit 4f6cbb3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/NetFabric.Numerics/Cartesian3/Quaternion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,7 @@ public static Quaternion<T> FromAxisAngle<T>(in Vector3<T> axis, Angle<Radians,
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>, ITrigonometricFunctions<T>
{
var halfAngle = angle / (T.One + T.One);
var sin = Angle.Sin(halfAngle);
var cos = Angle.Cos(halfAngle);
var (sin, cos) = Angle.SinCos(halfAngle);
return new(
axis.X * sin,
axis.Y * sin,
Expand Down
6 changes: 2 additions & 4 deletions src/NetFabric.Numerics/Polar/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,8 @@ public static PointReduced<TAngleUnits, TAngle, TRadius> Reduce<TAngleUnits, TAn
public static Cartesian2.Point<T> ToCartesian<T>(Point<Radians, T, T> point)
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>, ITrigonometricFunctions<T>
{
var x = point.Radius * Angle.Cos(point.Azimuth);
var y = point.Radius * Angle.Sin(point.Azimuth);

return new(x, y);
var (sin, cos) = Angle.SinCos(point.Azimuth);
return new(point.Radius * cos, point.Radius * sin);
}

/// <summary>
Expand Down
6 changes: 2 additions & 4 deletions src/NetFabric.Numerics/Spherical/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,8 @@ public static PointReduced<TAngleUnits, TAngle, TRadius> Reduce<TAngleUnits, TAn
public static Cartesian3.Point<T> ToCartesian<T>(Point<Radians, T, T> point)
where T : struct, IFloatingPoint<T>, IMinMaxValue<T>, ITrigonometricFunctions<T>
{
var sinAzimuth = Angle.Sin(point.Azimuth);
var cosAzimuth = Angle.Cos(point.Azimuth);
var sinPolar = Angle.Sin(point.Polar);
var cosPolar = Angle.Cos(point.Polar);
var (sinAzimuth, cosAzimuth) = Angle.SinCos(point.Azimuth);
var (sinPolar, cosPolar) = Angle.SinCos(point.Polar);

var x = T.CreateChecked(point.Radius * sinPolar * cosAzimuth);
var y = T.CreateChecked(point.Radius * sinPolar * sinAzimuth);
Expand Down

0 comments on commit 4f6cbb3

Please sign in to comment.