30 using System.Globalization;
31 using SiliconStudio.Core.Serialization;
33 namespace SiliconStudio.Core.Mathematics
45 public const float Degree = 0.002777777777777778f;
50 public const float Minute = 0.000046296296296296f;
55 public const float Second = 0.000000771604938272f;
60 public const float Radian = 0.159154943091895336f;
65 public const float Milliradian = 0.0001591549431f;
87 case AngleType.Revolution:
88 radians = MathUtil.RevolutionsToRadians(angle);
91 case AngleType.Degree:
92 radians = MathUtil.DegreesToRadians(angle);
95 case AngleType.Radian:
99 case AngleType.Gradian:
100 radians = MathUtil.GradiansToRadians(angle);
117 radians = arcLength / radius;
125 float newangle = (float)Math.IEEERemainder(radians,
MathUtil.
TwoPi);
128 newangle += MathUtil.TwoPi;
130 newangle -= MathUtil.TwoPi;
140 float newangle = radians % MathUtil.TwoPi;
143 newangle += MathUtil.TwoPi;
151 public float Revolutions
153 get {
return MathUtil.RadiansToRevolutions(radians); }
154 set { radians = MathUtil.RevolutionsToRadians(value); }
162 get {
return MathUtil.RadiansToDegrees(radians); }
163 set { radians = MathUtil.DegreesToRadians(value); }
176 float degrees = MathUtil.RadiansToDegrees(radians);
180 float degreesfloor = (float)Math.Ceiling(degrees);
181 return (degrees - degreesfloor) * 60.0f;
185 float degreesfloor = (float)Math.Floor(degrees);
186 return (degrees - degreesfloor) * 60.0f;
191 float degrees = MathUtil.RadiansToDegrees(radians);
192 float degreesfloor = (float)Math.Floor(degrees);
194 degreesfloor += value / 60.0f;
195 radians = MathUtil.DegreesToRadians(degreesfloor);
209 float degrees = MathUtil.RadiansToDegrees(radians);
213 float degreesfloor = (float)Math.Ceiling(degrees);
215 float minutes = (degrees - degreesfloor) * 60.0f;
216 float minutesfloor = (float)Math.Ceiling(minutes);
218 return (minutes - minutesfloor) * 60.0f;
222 float degreesfloor = (float)Math.Floor(degrees);
224 float minutes = (degrees - degreesfloor) * 60.0f;
225 float minutesfloor = (float)Math.Floor(minutes);
227 return (minutes - minutesfloor) * 60.0f;
232 float degrees = MathUtil.RadiansToDegrees(radians);
233 float degreesfloor = (float)Math.Floor(degrees);
235 float minutes = (degrees - degreesfloor) * 60.0f;
236 float minutesfloor = (float)Math.Floor(minutes);
238 minutesfloor += value / 60.0f;
239 degreesfloor += minutesfloor / 60.0f;
240 radians = MathUtil.DegreesToRadians(degreesfloor);
249 get {
return radians; }
250 set { radians = value; }
257 public float Milliradians
259 get {
return radians / (Milliradian * MathUtil.TwoPi); }
260 set { radians = value * (Milliradian * MathUtil.TwoPi); }
266 public float Gradians
268 get {
return MathUtil.RadiansToGradians(radians); }
269 set { radians = MathUtil.RadiansToGradians(value); }
278 get {
return radians == MathUtil.PiOverTwo; }
285 public bool IsStraight
287 get {
return radians == MathUtil.Pi; }
294 public bool IsFullRotation
296 get {
return radians == MathUtil.TwoPi; }
303 public bool IsOblique
305 get {
return WrapPositive(
this).radians != MathUtil.PiOverTwo; }
314 get {
return radians > 0.0 && radians < MathUtil.PiOverTwo; }
323 get {
return radians > MathUtil.PiOverTwo && radians < MathUtil.Pi; }
332 get {
return radians > MathUtil.Pi && radians < MathUtil.TwoPi; }
369 value.WrapPositive();
486 return left.radians == right.radians;
498 return left.radians != right.radians;
510 return left.radians < right.radians;
522 return left.radians > right.radians;
534 return left.radians <= right.radians;
546 return left.radians >= right.radians;
633 throw new ArgumentException(
"Argument must be of type Angle.",
"other");
635 float radians = ((AngleSingle)other).radians;
637 if (this.radians > radians)
640 if (this.radians < radians)
661 if (this.radians > other.
radians)
664 if (this.radians < other.
radians)
681 return this == other;
692 return string.Format(CultureInfo.CurrentCulture, MathUtil.RadiansToDegrees(radians).ToString(
"0.##°"));
707 return string.Format(CultureInfo.CurrentCulture,
"{0}°", MathUtil.RadiansToDegrees(radians).ToString(format, CultureInfo.CurrentCulture));
717 public string ToString(IFormatProvider formatProvider)
719 return string.Format(formatProvider, MathUtil.RadiansToDegrees(radians).ToString(
"0.##°"));
733 return ToString(formatProvider);
735 return string.Format(formatProvider,
"{0}°", MathUtil.RadiansToDegrees(radians).ToString(format, CultureInfo.CurrentCulture));
744 return (
int)(BitConverter.DoubleToInt64Bits(radians) %
int.MaxValue);
760 return (obj is
AngleSingle) && (
this == (AngleSingle)obj);
const float PiOverTwo
A value specifying the approximation of π/2 which is 90 degrees.
int CompareTo(object other)
Compares this instance to a specified object and returns an integer that indicates whether the value ...
const float TwoPi
A value specifying the approximation of 2π which is 360 degrees.
FbxDouble3 operator*(double factor, FbxDouble3 vector)
override string ToString()
Returns a System.String that represents this instance.
string ToString(string format, IFormatProvider formatProvider)
Returns a System.String that represents this instance.
void Wrap()
Wraps this SiliconStudio.Core.Mathematics.AngleSingle to be in the range [π, -π]. ...
int CompareTo(AngleSingle other)
Compares this instance to a second SiliconStudio.Core.Mathematics.AngleSingle and returns an integer ...
override bool Equals(object obj)
Returns a value that indicates whether the current instance and a specified object have the same valu...
string ToString(IFormatProvider formatProvider)
Returns a System.String that represents this instance.
void WrapPositive()
Wraps this SiliconStudio.Core.Mathematics.AngleSingle to be in the range [0, 2π). ...
override int GetHashCode()
Returns a hash code for this SiliconStudio.Core.Mathematics.AngleSingle instance. ...
Specifies an angle measurement in degrees.
const float Pi
A value specifying the approximation of π which is 180 degrees.
string ToString(string format)
Returns a System.String that represents this instance.
Specifies an angle measurement in radians.
static AngleSingle WrapPositive(AngleSingle value)
Wraps the SiliconStudio.Core.Mathematics.AngleSingle given in the value argument to be in the range [...
AngleSingle(float angle, AngleType type)
Initializes a new instance of the SiliconStudio.Core.Mathematics.AngleSingle structure with the given...
bool Equals(AngleSingle other)
Returns a value that indicates whether the current instance and a specified SiliconStudio.Core.Mathematics.AngleSingle object have the same value.
AngleSingle(float arcLength, float radius)
Initializes a new instance of the SiliconStudio.Core.Mathematics.AngleSingle structure using the arc ...
static AngleSingle Add(AngleSingle left, AngleSingle right)
Adds two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
static AngleSingle Wrap(AngleSingle value)
Wraps the SiliconStudio.Core.Mathematics.AngleSingle given in the value argument to be in the range [...
AngleType
Describes the type of angle.
float radians
The internal representation of the angle.
Represents a unit independant angle using a single-precision floating-point internal representation...
static AngleSingle Subtract(AngleSingle left, AngleSingle right)
Subtracts two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
_In_ size_t _In_ size_t _In_ DXGI_FORMAT format
static AngleSingle Max(AngleSingle left, AngleSingle right)
Compares two SiliconStudio.Core.Mathematics.AngleSingle instances and returns the greater angle...
static AngleSingle Multiply(AngleSingle left, AngleSingle right)
Multiplies two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result...
static AngleSingle Divide(AngleSingle left, AngleSingle right)
Divides two SiliconStudio.Core.Mathematics.AngleSingle objects and returns the result.
Specifies an angle measurement in gradians.
static AngleSingle Min(AngleSingle left, AngleSingle right)
Compares two SiliconStudio.Core.Mathematics.AngleSingle instances and returns the smaller angle...