From 4f6cbb34731517dcdf0b93631f052c781e07453d Mon Sep 17 00:00:00 2001 From: Antao Almada Date: Fri, 20 Oct 2023 11:16:15 +0100 Subject: [PATCH] Make use of Angle.SinCo --- src/NetFabric.Numerics/Cartesian3/Quaternion.cs | 3 +-- src/NetFabric.Numerics/Polar/Point.cs | 6 ++---- src/NetFabric.Numerics/Spherical/Point.cs | 6 ++---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/NetFabric.Numerics/Cartesian3/Quaternion.cs b/src/NetFabric.Numerics/Cartesian3/Quaternion.cs index 823664f..373e970 100644 --- a/src/NetFabric.Numerics/Cartesian3/Quaternion.cs +++ b/src/NetFabric.Numerics/Cartesian3/Quaternion.cs @@ -328,8 +328,7 @@ public static Quaternion FromAxisAngle(in Vector3 axis, Angle, IMinMaxValue, ITrigonometricFunctions { 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, diff --git a/src/NetFabric.Numerics/Polar/Point.cs b/src/NetFabric.Numerics/Polar/Point.cs index 3b4e618..db0da67 100644 --- a/src/NetFabric.Numerics/Polar/Point.cs +++ b/src/NetFabric.Numerics/Polar/Point.cs @@ -354,10 +354,8 @@ public static PointReduced Reduce ToCartesian(Point point) where T : struct, IFloatingPoint, IMinMaxValue, ITrigonometricFunctions { - 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); } /// diff --git a/src/NetFabric.Numerics/Spherical/Point.cs b/src/NetFabric.Numerics/Spherical/Point.cs index 25635ad..b5b1ac6 100644 --- a/src/NetFabric.Numerics/Spherical/Point.cs +++ b/src/NetFabric.Numerics/Spherical/Point.cs @@ -369,10 +369,8 @@ public static PointReduced Reduce ToCartesian(Point point) where T : struct, IFloatingPoint, IMinMaxValue, ITrigonometricFunctions { - 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);