diff --git a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
index da9aad6..535df3f 100644
--- a/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
+++ b/OSCADSharp/OSCADSharp.ConsoleTests/Program.cs
@@ -13,7 +13,7 @@ namespace OSCADSharp.ConsoleTests
{
static void Main(string[] args)
{
- var cube = new Cube(50, 50, 50).Translate(10, 10, 0);
+ var cube = new Cube(50, 50, 50, true).Translate(30, 30, 30).Rotate(25, 45, -90);
var pos = cube.Position();
var cyl1 = new Cylinder(1, 100, true).Translate(pos);
diff --git a/OSCADSharp/OSCADSharp/Spatial/Matrix.cs b/OSCADSharp/OSCADSharp/Spatial/Matrix.cs
index 9e22dd8..981acd8 100644
--- a/OSCADSharp/OSCADSharp/Spatial/Matrix.cs
+++ b/OSCADSharp/OSCADSharp/Spatial/Matrix.cs
@@ -57,6 +57,7 @@ namespace OSCADSharp.Spatial
// and add it to the result in the corresponding row/column
for (int leftMatrixColumn = 0; leftMatrixColumn < this.ColumnCount; leftMatrixColumn++)
{
+ result.Add(0);
result[currentRowInResult * other.ColumnCount + column] +=
this.values[row * this.ColumnCount + leftMatrixColumn] *
otherValues[leftMatrixColumn * other.ColumnCount + column];
@@ -93,6 +94,9 @@ namespace OSCADSharp.Spatial
/// Transformation matrix to perform the rotation
internal static Matrix XRotation(double angle)
{
+ if (angle == 0)
+ return Identity;
+
double radAngle = toRadians(angle);
double[] rotationArr = new double[] {
1 , 0, 0, 0,
@@ -112,6 +116,9 @@ namespace OSCADSharp.Spatial
/// Transformation matrix to perform the rotation
internal static Matrix YRotation(double angle)
{
+ if (angle == 0)
+ return Identity;
+
double radAngle = toRadians(angle);
double[] rotationArr = new double[] {
Math.Cos(radAngle), 0, -Math.Sin(radAngle), 0,
@@ -131,6 +138,9 @@ namespace OSCADSharp.Spatial
/// Transformation matrix to perform the rotation
internal static Matrix ZRotation(double angle)
{
+ if (angle == 0)
+ return Identity;
+
double radAngle = toRadians(angle);
double[] rotationArr = new double[] {
Math.Cos(radAngle), Math.Sin(radAngle), 0, 0,
@@ -152,12 +162,10 @@ namespace OSCADSharp.Spatial
/// Point after rotation
internal static Vector3 GetRotatedPoint(Vector3 point, double xAngle, double yAngle, double zAngle)
{
- Matrix transformation = XRotation(xAngle)
- .Multiply(YRotation(yAngle))
- .Multiply(ZRotation(zAngle));
-
- double[] result = transformation.Multiply(point.ToMatrix()).GetValues();
- return new Vector3(result[0], result[1], result[2]);
+ var x = XRotation(-xAngle).Multiply(point.ToMatrix());
+ var y = YRotation(-yAngle).Multiply(x);
+ var z = ZRotation(-zAngle).Multiply(y).GetValues();
+ return new Vector3(z[0], z[1], z[2]);
}
#endregion
}
diff --git a/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs b/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs
index aa7c787..c83aa95 100644
--- a/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs
+++ b/OSCADSharp/OSCADSharp/Transforms/RotatedObject.cs
@@ -1,4 +1,5 @@
using OSCADSharp.Scripting;
+using OSCADSharp.Spatial;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -51,7 +52,7 @@ namespace OSCADSharp.Transforms
public override Vector3 Position()
{
- throw new NotImplementedException();
+ return Matrix.GetRotatedPoint(this.obj.Position(), this.Angle.X, this.Angle.Y, this.Angle.Z);
}
}
}