Merge commit '1855aa0705deb54be7886fd6572bf186365559a6'
This commit is contained in:
commit
cd6ec2ee1e
@ -57,7 +57,7 @@ namespace LinearAlgebra {
|
||||
public readonly float inRevolutions => this.value / 360.0f;
|
||||
|
||||
public override string ToString() {
|
||||
return $"{this.inDegrees} deg.";
|
||||
return $"{this.inDegrees}\u00B0";
|
||||
}
|
||||
|
||||
public static readonly AngleFloat zero = Degrees(0);
|
||||
|
||||
@ -124,7 +124,7 @@ namespace LinearAlgebra {
|
||||
#endif
|
||||
|
||||
public override readonly string ToString() {
|
||||
return $"Spherical(h: {this.direction.horizontal}, v: {this.direction.vertical}, distance: {this.distance})";
|
||||
return $"Spherical({this.distance}, h: {this.direction.horizontal}, v: {this.direction.vertical})";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -119,6 +119,10 @@ namespace LinearAlgebra {
|
||||
return new Vector3Float(horizontal, vertical, depth);
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return $"({this.horizontal}, {this.vertical}, {this.depth})";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A vector with zero for all axis
|
||||
/// </summary>
|
||||
|
||||
@ -103,7 +103,7 @@ namespace LinearAlgebra.Test {
|
||||
|
||||
[Test]
|
||||
public void ToVector3AndBack2() {
|
||||
Direction d1 = Direction.Degrees(135, 85);
|
||||
Direction d1 = Direction.Degrees(-135, 85);
|
||||
Vector3Float v = d1.ToVector3();
|
||||
Direction d2 = Direction.FromVector3(v);
|
||||
Assert.AreEqual(d1.horizontal.inDegrees, d2.horizontal.inDegrees, 0.0001f);
|
||||
|
||||
@ -234,6 +234,30 @@ namespace LinearAlgebra.Test {
|
||||
Assert.AreEqual(MathF.Cos(alpha), avg.distance, 1e-4f);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Average_CompareWithVector3() {
|
||||
// Four vectors around azimuth 0, pi/2, pi, 3pi/2 at same polar angle from vertical (alpha)
|
||||
float alpha = MathF.PI / 6f; // polar angle from vertical
|
||||
float elevation = MathF.PI / 2f - alpha; // convert polar-from-vertical to elevation
|
||||
List<Spherical> dirs = new List<Spherical> {
|
||||
new(1f, Direction.Radians(0f, elevation)),
|
||||
new(2f, Direction.Radians(MathF.PI/2, elevation+1)),
|
||||
new(3f, Direction.Radians(MathF.PI, elevation+2)),
|
||||
new(4f, Direction.Radians(3*MathF.PI/2, elevation+3))
|
||||
};
|
||||
|
||||
Spherical avg = Spherical.Average(dirs);
|
||||
|
||||
Vector3Float r = Vector3Float.zero;
|
||||
foreach (Spherical dir in dirs) {
|
||||
r += dir.ToVector3();
|
||||
}
|
||||
r = r / 4;
|
||||
Spherical avg2 = Spherical.FromVector3(r);
|
||||
|
||||
Assert.AreEqual(avg, avg2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user