Possible functioning implementation of Rotate's point interpolation (at least with center=true). Further testing needed.

This commit is contained in:
Mike Smith 2016-02-15 00:31:20 -08:00
parent 2a7ee3ab63
commit 1be343fadc
3 changed files with 17 additions and 8 deletions

View File

@ -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);

View File

@ -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
/// <returns>Transformation matrix to perform the rotation</returns>
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
/// <returns>Transformation matrix to perform the rotation</returns>
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
/// <returns>Transformation matrix to perform the rotation</returns>
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
/// <returns>Point after rotation</returns>
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
}

View File

@ -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);
}
}
}