static public Coords Shear(Coords position, float x, float y, float z) { float[] shearValues = { 1, x, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1 }; Matrix shearMatrix = new Matrix(4, 4, shearValues); Matrix pos = new Matrix(4, 1, position.AsFloats()); Matrix shear = shearMatrix * pos; return(shear.AsCoords()); }
static public Coords Reflect(Coords position) { float[] reflectValues = { -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; Matrix reflectMatrix = new Matrix(4, 4, reflectValues); Matrix pos = new Matrix(4, 1, position.AsFloats()); Matrix result = reflectMatrix * pos; return(result.AsCoords()); }
static public Coords Shear(Coords position, float shearX, float shearY, float shearZ) { float[] shearValues = { 1, shearY, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; Matrix shearMatrix = new Matrix(4, 4, shearValues); Matrix pos = new Matrix(4, 1, position.AsFloats()); Matrix result = shearMatrix * pos; return(result.AsCoords()); }
static public Coords Scale(Coords position, float scaleX, float scaleY, float scaleZ) { float[] scaleValues = { scaleX, 0, 0, 0, 0, scaleY, 0, 0, 0, 0, scaleZ, 0, 0, 0, 0, 1 }; Matrix scaleMatrix = new Matrix(4, 4, scaleValues); Matrix pos = new Matrix(4, 1, position.AsFloats()); Matrix result = scaleMatrix * pos; return(result.AsCoords()); }
static public Coords Translate(Coords position, Coords vector) { float[] translateValues = { 1, 0, 0, vector.x, 0, 1, 0, vector.y, 0, 0, 1, vector.z, 0, 0, 0, 1 }; Matrix translateMatrix = new Matrix(4, 4, translateValues); Matrix pos = new Matrix(4, 1, position.AsFloats()); Matrix result = translateMatrix * pos; return(result.AsCoords()); }
static public Coords Rotate(Coords point, float anglex, bool clockwisex, float angley, bool clockwisey, float anglez, bool clockwisez) //in radians { if (clockwisex) { anglex = 2 * Mathf.PI - anglex; } if (clockwisey) { angley = 2 * Mathf.PI - angley; } if (clockwisez) { anglez = 2 * Mathf.PI - anglez; } float [] roationValesX = { 1, 0, 0, 0, 0, Mathf.Cos(anglex), -Mathf.Sin(anglex), 0, 0, Mathf.Sin(anglex), Mathf.Cos(anglex), 0, 0, 0, 0, 1 }; Matrix XRoll = new Matrix(4, 4, roationValesX); float [] roationValesY = { Mathf.Cos(angley), 0, Mathf.Sin(angley), 0, 0, 1, 0, 0, -Mathf.Sin(angley), 0, Mathf.Cos(angley), 0, 0, 0, 0, 1 }; Matrix YRoll = new Matrix(4, 4, roationValesY); float [] roationValesZ = { Mathf.Cos(anglez), -Mathf.Sin(anglez), 0, 0, Mathf.Sin(anglez), Mathf.Cos(anglez), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; Matrix ZRoll = new Matrix(4, 4, roationValesZ); Matrix pos = new Matrix(4, 1, point.AsFloats()); Matrix result = ZRoll * YRoll * XRoll * pos; return(result.AsCords()); }
static public Coords Rotate(Coords position, Rotation r) { r = CheckForClockwise(r); float[] xRollValues = GetRollValues(r, "x"); float[] yRollValues = GetRollValues(r, "y"); float[] zRollValues = GetRollValues(r, "z"); Matrix xRoll = new Matrix(4, 4, xRollValues); Matrix yRoll = new Matrix(4, 4, yRollValues); Matrix zRoll = new Matrix(4, 4, zRollValues); Matrix pos = new Matrix(4, 1, position.AsFloats()); Matrix rotation = zRoll * yRoll * xRoll * pos; return(rotation.AsCoords()); }
static public Coords Rotate(Coords position, float angleX, bool clockwiseX, float angleY, bool clockwiseY, float angleZ, bool clockwiseZ) { if (clockwiseX) { angleX = 2 * Mathf.PI - angleX; } if (clockwiseY) { angleY = 2 * Mathf.PI - angleY; } if (clockwiseZ) { angleZ = 2 * Mathf.PI - angleZ; } float[] xrollValues = { 1, 0, 0, 0, 0, Mathf.Cos(angleX), -Mathf.Sin(angleX), 0, 0, Mathf.Sin(angleX), Mathf.Cos(angleX), 0, 0, 0, 0, 1 }; Matrix XRoll = new Matrix(4, 4, xrollValues); float[] yrollValues = { Mathf.Cos(angleY), 0, Mathf.Sin(angleY), 0, 0, 1, 0, 0, -Mathf.Sin(angleY), 0, Mathf.Cos(angleY), 0, 0, 0, 0, 1 }; Matrix YRoll = new Matrix(4, 4, yrollValues); float[] zrollValues = { Mathf.Cos(angleZ), -Mathf.Sin(angleZ), 0, 0, Mathf.Sin(angleZ), Mathf.Cos(angleZ), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; Matrix ZRoll = new Matrix(4, 4, zrollValues); Matrix pos = new Matrix(4, 1, position.AsFloats()); Matrix result = ZRoll * YRoll * XRoll * pos; return(result.AsCoords()); }
static public Coords QRotate(Coords position, Coords axis, float angle /*degree*/) { Coords aNormal = Coords.GetNormal(axis); float w = Mathf.Cos(angle * Mathf.Deg2Rad / 2); float s = Mathf.Sin(angle * Mathf.Deg2Rad / 2); //quaternion equation. Coords q = new Coords(aNormal.x * s, aNormal.y * s, aNormal.z * s, w); float[] quaternionValues = { 1 - 2 * q.y * q.y - 2 * q.z * q.z, 2 * q.x * q.y - 2 * q.w * q.z, 2 * q.x * q.z + 2 * q.w * q.y, 0, 2 * q.x * q.y + 2 * q.w * q.z, 1 - 2 * q.x * q.x - 2 * q.z * q.z, 2 * q.y * q.z - 2 * q.w * q.x, 0, 2 * q.x * q.z - 2 * q.w * q.y, 2 * q.y * q.z + 2 * q.w * q.x, 1 - 2 * q.x * q.x - 2 * q.y * q.y, 0, 0, 0, 0, 1 }; Matrix quaternionMatrix = new Matrix(4, 4, quaternionValues); Matrix pos = new Matrix(4, 1, position.AsFloats()); Matrix result = quaternionMatrix * pos; return(result.AsCords()); }