public void AddPosition(LayerCyl layer, Vector2D vPosition) { Matrix4D matRot = Matrix4D.Identity; Vector3D vTranslation = Vector3D.Zero; if (_swapped) { matRot = new Matrix4D( 0.0, -1.0, 0.0, 0.0 , 1.0, 0.0, 0.0, 0.0 , 0.0, 0.0, 1.0, 0.0 , 0.0, 0.0, 0.0, 1.0 ); vTranslation = new Vector3D(layer.PalletLength, 0.0, 0.0); } Transform3D transfRot = new Transform3D(matRot); matRot.M14 = vTranslation[0]; matRot.M24 = vTranslation[1]; matRot.M34 = vTranslation[2]; Transform3D transfRotTranslation = new Transform3D(matRot); Vector3D vPositionSwapped = transfRotTranslation.transform(new Vector3D(vPosition.X, vPosition.Y, 0.0)); if (!layer.IsValidPosition(new Vector2D(vPositionSwapped.X, vPositionSwapped.Y))) { _log.Warn(string.Format("Attempt to add an invalid position in pattern = {0}, Swapped = true", this.Name)); return; } layer.Add(new Vector2D(vPositionSwapped.X, vPositionSwapped.Y)); }
public void AddPosition(Layer layer, Vector2D vPosition, HalfAxis.HAxis lengthAxis, HalfAxis.HAxis widthAxis) { Matrix4D matRot = Matrix4D.Identity; Vector3D vTranslation = Vector3D.Zero; if (_swapped && !layer.Inversed) { matRot = new Matrix4D( 0.0, -1.0, 0.0, 0.0 , 1.0, 0.0, 0.0, 0.0 , 0.0, 0.0, 1.0, 0.0 , 0.0, 0.0, 0.0, 1.0 ); vTranslation = new Vector3D(layer.PalletLength, 0.0, 0.0); } else if (!_swapped && layer.Inversed) { matRot = new Matrix4D( -1.0, 0.0, 0.0, 0.0 , 0.0, -1.0, 0.0, 0.0 , 0.0, 0.0, 1.0, 0.0 , 0.0, 0.0, 0.0, 1.0 ); vTranslation = new Vector3D(layer.PalletLength, layer.PalletWidth, 0.0); } else if (_swapped && layer.Inversed) { matRot = new Matrix4D( 0.0, 1.0, 0.0, 0.0 , -1.0, 0.0, 0.0, 0.0 , 0.0, 0.0, 1.0, 0.0 , 0.0, 0.0, 0.0, 1.0 ); vTranslation = new Vector3D(0.0, layer.PalletWidth, 0.0); } Transform3D transfRot = new Transform3D(matRot); HalfAxis.HAxis lengthAxisSwapped = StackBuilder.Basics.HalfAxis.ToHalfAxis(transfRot.transform(StackBuilder.Basics.HalfAxis.ToVector3D(lengthAxis))); HalfAxis.HAxis widthAxisSwapped = StackBuilder.Basics.HalfAxis.ToHalfAxis(transfRot.transform(StackBuilder.Basics.HalfAxis.ToVector3D(widthAxis))); matRot.M14 = vTranslation[0]; matRot.M24 = vTranslation[1]; matRot.M34 = vTranslation[2]; Transform3D transfRotTranslation = new Transform3D(matRot); Vector3D vPositionSwapped = transfRotTranslation.transform(new Vector3D(vPosition.X, vPosition.Y, 0.0)); if (!layer.IsValidPosition(new Vector2D(vPositionSwapped.X, vPositionSwapped.Y), lengthAxisSwapped, widthAxisSwapped)) { _log.Warn(string.Format("Attempt to add an invalid position in pattern = {0}, Variant = {1}, Swapped = true", this.Name, _variantIndex)); return; } layer.AddPosition(new Vector2D(vPositionSwapped.X, vPositionSwapped.Y), lengthAxisSwapped, widthAxisSwapped); }
public void AddPosition(CylLoad load, CylPosition pos) { Matrix4D matRot = Matrix4D.Identity; Vector3D vTranslation = Vector3D.Zero; if (_swapped) { matRot = new Matrix4D( 0.0, -1.0, 0.0, 0.0 , 1.0, 0.0, 0.0, 0.0 , 0.0, 0.0, 1.0, 0.0 , 0.0, 0.0, 0.0, 1.0 ); vTranslation = new Vector3D(load.PalletLength, 0.0, 0.0); matRot.M14 = vTranslation[0]; matRot.M24 = vTranslation[1]; matRot.M34 = vTranslation[2]; } load.Add(pos.Transform(new Transform3D(matRot))); }
/// <summary> /// Multiplies two matrices and put the result in a third matrix. /// </summary> /// <param name="left">A <see cref="Matrix4D"/> instance.</param> /// <param name="right">A <see cref="Matrix4D"/> instance.</param> /// <param name="result">A <see cref="Matrix4D"/> instance to hold the result.</param> public static void Multiply(Matrix4D left, Matrix4D right, ref Matrix4D result) { result.M11 = left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41; result.M12 = left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32 + left.M14 * right.M42; result.M13 = left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33 + left.M14 * right.M43; result.M14 = left.M11 * right.M14 + left.M12 * right.M24 + left.M13 * right.M34 + left.M14 * right.M44; result.M21 = left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31 + left.M24 * right.M41; result.M22 = left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32 + left.M24 * right.M42; result.M23 = left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33 + left.M24 * right.M43; result.M24 = left.M21 * right.M14 + left.M22 * right.M24 + left.M23 * right.M34 + left.M24 * right.M44; result.M31 = left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31 + left.M34 * right.M41; result.M32 = left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32 + left.M34 * right.M42; result.M33 = left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33 + left.M34 * right.M43; result.M34 = left.M31 * right.M14 + left.M32 * right.M24 + left.M33 * right.M34 + left.M34 * right.M44; result.M41 = left.M41 * right.M11 + left.M42 * right.M21 + left.M43 * right.M31 + left.M44 * right.M41; result.M42 = left.M41 * right.M12 + left.M42 * right.M22 + left.M43 * right.M32 + left.M44 * right.M42; result.M43 = left.M41 * right.M13 + left.M42 * right.M23 + left.M43 * right.M33 + left.M44 * right.M43; result.M44 = left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44; }
/// <summary> /// Multiplies two matrices. /// </summary> /// <param name="left">A <see cref="Matrix4D"/> instance.</param> /// <param name="right">A <see cref="Matrix4D"/> instance.</param> /// <returns>A new <see cref="Matrix4D"/> instance containing the result.</returns> public static Matrix4D Multiply(Matrix4D left, Matrix4D right) { return new Matrix4D( left.M11 * right.M11 + left.M12 * right.M21 + left.M13 * right.M31 + left.M14 * right.M41, left.M11 * right.M12 + left.M12 * right.M22 + left.M13 * right.M32 + left.M14 * right.M42, left.M11 * right.M13 + left.M12 * right.M23 + left.M13 * right.M33 + left.M14 * right.M43, left.M11 * right.M14 + left.M12 * right.M24 + left.M13 * right.M34 + left.M14 * right.M44, left.M21 * right.M11 + left.M22 * right.M21 + left.M23 * right.M31 + left.M24 * right.M41, left.M21 * right.M12 + left.M22 * right.M22 + left.M23 * right.M32 + left.M24 * right.M42, left.M21 * right.M13 + left.M22 * right.M23 + left.M23 * right.M33 + left.M24 * right.M43, left.M21 * right.M14 + left.M22 * right.M24 + left.M23 * right.M34 + left.M24 * right.M44, left.M31 * right.M11 + left.M32 * right.M21 + left.M33 * right.M31 + left.M34 * right.M41, left.M31 * right.M12 + left.M32 * right.M22 + left.M33 * right.M32 + left.M34 * right.M42, left.M31 * right.M13 + left.M32 * right.M23 + left.M33 * right.M33 + left.M34 * right.M43, left.M31 * right.M14 + left.M32 * right.M24 + left.M33 * right.M34 + left.M34 * right.M44, left.M41 * right.M11 + left.M42 * right.M21 + left.M43 * right.M31 + left.M44 * right.M41, left.M41 * right.M12 + left.M42 * right.M22 + left.M43 * right.M32 + left.M44 * right.M42, left.M41 * right.M13 + left.M42 * right.M23 + left.M43 * right.M33 + left.M44 * right.M43, left.M41 * right.M14 + left.M42 * right.M24 + left.M43 * right.M34 + left.M44 * right.M44 ); }
/// <summary> /// Subtracts a scalar from a matrix and put the result in a third matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix4D"/> instance.</param> /// <param name="scalar">A double-precision floating-point number.</param> /// <param name="result">A <see cref="Matrix4D"/> instance to hold the result.</param> public static void Subtract(Matrix4D matrix, double scalar, ref Matrix4D result) { result.M11 = matrix.M11 - scalar; result.M12 = matrix.M12 - scalar; result.M13 = matrix.M13 - scalar; result.M14 = matrix.M14 - scalar; result.M21 = matrix.M21 - scalar; result.M22 = matrix.M22 - scalar; result.M23 = matrix.M23 - scalar; result.M24 = matrix.M24 - scalar; result.M31 = matrix.M31 - scalar; result.M32 = matrix.M32 - scalar; result.M33 = matrix.M33 - scalar; result.M34 = matrix.M34 - scalar; result.M41 = matrix.M41 - scalar; result.M42 = matrix.M42 - scalar; result.M43 = matrix.M43 - scalar; result.M44 = matrix.M44 - scalar; }
LayerPosition ApplyReflection(LayerPosition layerPos, Matrix4D matRot, Vector3D vTranslation) { Vector3D dimensions = Analysis.ContentDimensions; Transform3D transfRot = new Transform3D(matRot); HalfAxis.HAxis axisLength = HalfAxis.ToHalfAxis(transfRot.transform(HalfAxis.ToVector3D(layerPos.LengthAxis))); HalfAxis.HAxis axisWidth = HalfAxis.ToHalfAxis(transfRot.transform(HalfAxis.ToVector3D(layerPos.WidthAxis))); matRot.M14 = vTranslation[0]; matRot.M24 = vTranslation[1]; matRot.M34 = vTranslation[2]; Transform3D transfRotTranslation = new Transform3D(matRot); Vector3D transPos = transfRotTranslation.transform( new Vector3D(layerPos.Position.X, layerPos.Position.Y, layerPos.Position.Z) ); return new LayerPosition( new Vector3D(transPos.X, transPos.Y, transPos.Z) - dimensions.Z * Vector3D.CrossProduct(HalfAxis.ToVector3D(axisLength), HalfAxis.ToVector3D(axisWidth)) , axisLength , axisWidth); }
public Transform3D(Transform3D transf) { _mat = transf._mat.Clone(); }
/// <summary> /// Transposes a matrix. /// </summary> /// <param name="m">A <see cref="Matrix4D"/> instance.</param> /// <returns>A new <see cref="Matrix4D"/> instance containing the transposed matrix.</returns> public static Matrix4D Transpose(Matrix4D m) { Matrix4D t = new Matrix4D(m); t.Transpose(); return t; }
/// <summary> /// Adds two matrices and put the result in a third matrix. /// </summary> /// <param name="left">A <see cref="Matrix4D"/> instance.</param> /// <param name="right">A <see cref="Matrix4D"/> instance.</param> /// <param name="result">A <see cref="Matrix4D"/> instance to hold the result.</param> public static void Add(Matrix4D left, Matrix4D right, ref Matrix4D result) { result.M11 = left.M11 + right.M11; result.M12 = left.M12 + right.M12; result.M13 = left.M13 + right.M13; result.M14 = left.M14 + right.M14; result.M21 = left.M21 + right.M21; result.M22 = left.M22 + right.M22; result.M23 = left.M23 + right.M23; result.M24 = left.M24 + right.M24; result.M31 = left.M31 + right.M31; result.M32 = left.M32 + right.M32; result.M33 = left.M33 + right.M33; result.M34 = left.M34 + right.M34; result.M41 = left.M41 + right.M41; result.M42 = left.M42 + right.M42; result.M43 = left.M43 + right.M43; result.M44 = left.M44 + right.M44; }
/// <summary> /// Adds a matrix and a scalar. /// </summary> /// <param name="matrix">A <see cref="Matrix4D"/> instance.</param> /// <param name="scalar">A double-precision floating-point number.</param> /// <returns>A new <see cref="Matrix4D"/> instance containing the sum.</returns> public static Matrix4D Add(Matrix4D matrix, double scalar) { return new Matrix4D( matrix.M11 + scalar, matrix.M12 + scalar, matrix.M13 + scalar, matrix.M14 + scalar, matrix.M21 + scalar, matrix.M22 + scalar, matrix.M23 + scalar, matrix.M24 + scalar, matrix.M31 + scalar, matrix.M32 + scalar, matrix.M33 + scalar, matrix.M34 + scalar, matrix.M41 + scalar, matrix.M42 + scalar, matrix.M43 + scalar, matrix.M44 + scalar ); }
/// <summary> /// Adds two matrices. /// </summary> /// <param name="left">A <see cref="Matrix4D"/> instance.</param> /// <param name="right">A <see cref="Matrix4D"/> instance.</param> /// <returns>A new <see cref="Matrix4D"/> instance containing the sum.</returns> public static Matrix4D Add(Matrix4D left, Matrix4D right) { return new Matrix4D( left.M11 + right.M11, left.M12 + right.M12, left.M13 + right.M13, left.M14 + right.M14, left.M21 + right.M21, left.M22 + right.M22, left.M23 + right.M23, left.M24 + right.M24, left.M31 + right.M31, left.M32 + right.M32, left.M33 + right.M33, left.M34 + right.M34, left.M41 + right.M41, left.M42 + right.M42, left.M43 + right.M43, left.M44 + right.M44 ); }
/// <summary> /// Converts the specified string to its <see cref="Matrix4D"/> equivalent. /// A return value indicates whether the conversion succeeded or failed. /// </summary> /// <param name="value">A string representation of a <see cref="Matrix4D"/>.</param> /// <param name="result"> /// When this method returns, if the conversion succeeded, /// contains a <see cref="Matrix4D"/> representing the vector specified by <paramref name="value"/>. /// </param> /// <returns><see langword="true"/> if value was converted successfully; otherwise, <see langword="false"/>.</returns> /// <remarks> /// The string should be in the following form: "4x4..matrix elements..>".<br/> /// Exmaple : "4x4[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]" /// </remarks> public static bool TryParse(string value, out Matrix4D result) { Regex r = new Regex(regularExp, RegexOptions.Singleline); Match m = r.Match(value); if (m.Success) { result = new Matrix4D( double.Parse(m.Result("${m11}")), double.Parse(m.Result("${m12}")), double.Parse(m.Result("${m13}")), double.Parse(m.Result("${m14}")), double.Parse(m.Result("${m21}")), double.Parse(m.Result("${m22}")), double.Parse(m.Result("${m23}")), double.Parse(m.Result("${m24}")), double.Parse(m.Result("${m31}")), double.Parse(m.Result("${m32}")), double.Parse(m.Result("${m33}")), double.Parse(m.Result("${m34}")), double.Parse(m.Result("${m41}")), double.Parse(m.Result("${m42}")), double.Parse(m.Result("${m43}")), double.Parse(m.Result("${m44}")) ); return true; } result = Matrix4D.Zero; return false; }
/// <summary> /// Initializes a new instance of the <see cref="Matrix4D"/> class using a given matrix. /// </summary> public Matrix4D(Matrix4D m) { _m11 = m.M11; _m12 = m.M12; _m13 = m.M13; _m14 = m.M14; _m21 = m.M21; _m22 = m.M22; _m23 = m.M23; _m24 = m.M24; _m31 = m.M31; _m32 = m.M32; _m33 = m.M33; _m34 = m.M34; _m41 = m.M41; _m42 = m.M42; _m43 = m.M43; _m44 = m.M44; }
public Transform3D GetWorldToEyeTransformation() { /* Orthographic transformation chain • Start with coordinates in object’s local coordinates • Transform into world coords (modeling transform, Mm) • Transform into eye coords (camera xf., Mcam = Fc–1) • Orthographic projection, Morth • Viewport transform, Mvp ps = Mvp*Morth*Mcam*Mm*po */ Vector3D zaxis = _vCameraPos - _vTarget; zaxis.Normalize(); Vector3D up = Vector3D.ZAxis; Vector3D xaxis = Vector3D.CrossProduct(up, zaxis); if (Vector3D.CrossProduct(up, zaxis).GetLengthSquared() < 0.0001) { up = Vector3D.ZAxis; xaxis = Vector3D.XAxis; } xaxis.Normalize(); Vector3D yaxis = Vector3D.CrossProduct(zaxis, xaxis); Matrix4D Mcam = new Matrix4D( xaxis.X, xaxis.Y, xaxis.Z, -Vector3D.DotProduct(_vCameraPos - _vTarget, xaxis), yaxis.X, yaxis.Y, yaxis.Z, -Vector3D.DotProduct(_vCameraPos - _vTarget, yaxis), -zaxis.X, -zaxis.Y, -zaxis.Z, -Vector3D.DotProduct(_vCameraPos - _vTarget, -zaxis), 0.0, 0.0, 0.0, 1.0 ); return new Transform3D(Mcam); }
/// <summary> /// Transforms a given vector by a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix4D"/> instance.</param> /// <param name="vector">A <see cref="Vector4D"/> instance.</param> /// <returns>A new <see cref="Vector4D"/> instance containing the result.</returns> public static Vector4D Transform(Matrix4D matrix, Vector4D vector) { return new Vector4D( (matrix.M11 * vector.X) + (matrix.M12 * vector.Y) + (matrix.M13 * vector.Z) + (matrix.M14 * vector.W), (matrix.M21 * vector.X) + (matrix.M22 * vector.Y) + (matrix.M23 * vector.Z) + (matrix.M24 * vector.W), (matrix.M31 * vector.X) + (matrix.M32 * vector.Y) + (matrix.M33 * vector.Z) + (matrix.M34 * vector.W), (matrix.M41 * vector.X) + (matrix.M42 * vector.Y) + (matrix.M43 * vector.Z) + (matrix.M44 * vector.W)); }
/// <summary> /// Transforms a given vector by a matrix and put the result in a vector. /// </summary> /// <param name="matrix">A <see cref="Matrix4D"/> instance.</param> /// <param name="vector">A <see cref="Vector4D"/> instance.</param> /// <param name="result">A <see cref="Vector4D"/> instance to hold the result.</param> public static void Transform(Matrix4D matrix, Vector4D vector, ref Vector4D result) { result.X = (matrix.M11 * vector.X) + (matrix.M12 * vector.Y) + (matrix.M13 * vector.Z) + (matrix.M14 * vector.W); result.Y = (matrix.M21 * vector.X) + (matrix.M22 * vector.Y) + (matrix.M23 * vector.Z) + (matrix.M24 * vector.W); result.Z = (matrix.M31 * vector.X) + (matrix.M32 * vector.Y) + (matrix.M33 * vector.Z) + (matrix.M34 * vector.W); result.W = (matrix.M41 * vector.X) + (matrix.M42 * vector.Y) + (matrix.M43 * vector.Z) + (matrix.M44 * vector.W); }
/// <summary> /// Adds a matrix and a scalar and put the result in a third matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix4D"/> instance.</param> /// <param name="scalar">A double-precision floating-point number.</param> /// <param name="result">A <see cref="Matrix4D"/> instance to hold the result.</param> public static void Add(Matrix4D matrix, double scalar, ref Matrix4D result) { result.M11 = matrix.M11 + scalar; result.M12 = matrix.M12 + scalar; result.M13 = matrix.M13 + scalar; result.M14 = matrix.M14 + scalar; result.M21 = matrix.M21 + scalar; result.M22 = matrix.M22 + scalar; result.M23 = matrix.M23 + scalar; result.M24 = matrix.M24 + scalar; result.M31 = matrix.M31 + scalar; result.M32 = matrix.M32 + scalar; result.M33 = matrix.M33 + scalar; result.M34 = matrix.M34 + scalar; result.M41 = matrix.M41 + scalar; result.M42 = matrix.M42 + scalar; result.M43 = matrix.M43 + scalar; result.M44 = matrix.M44 + scalar; }
public Transform3D(Matrix4D mat) { _mat = mat.Clone(); }
/// <summary> /// Subtracts a matrix from a matrix. /// </summary> /// <param name="left">A <see cref="Matrix4D"/> instance to subtract from.</param> /// <param name="right">A <see cref="Matrix4D"/> instance to subtract.</param> /// <returns>A new <see cref="Matrix4D"/> instance containing the difference.</returns> /// <remarks>result[x][y] = left[x][y] - right[x][y]</remarks> public static Matrix4D Subtract(Matrix4D left, Matrix4D right) { return new Matrix4D( left.M11 - right.M11, left.M12 - right.M12, left.M13 - right.M13, left.M14 - right.M14, left.M21 - right.M21, left.M22 - right.M22, left.M23 - right.M23, left.M24 - right.M24, left.M31 - right.M31, left.M32 - right.M32, left.M33 - right.M33, left.M34 - right.M34, left.M41 - right.M41, left.M42 - right.M42, left.M43 - right.M43, left.M44 - right.M44 ); }
public BoxLayer GetBoxLayer(int iLayerIndex, ref bool hasInterlayer, ref double zInterlayer) { if (null == _parentAnalysis) throw new Exception("_parentAnalysis not set."); double interlayerThickness = (null != _parentAnalysis.InterlayerProperties) ? _parentAnalysis.InterlayerProperties.Thickness : 0.0; double packHeight = _parentAnalysis.PackProperties.Height; double zLow = _parentAnalysis.PalletProperties.Height; int i = 0; while (i <= iLayerIndex-1) { LayerDescriptor desc = _listLayers[i]; zLow += (desc.HasInterlayer ? interlayerThickness : 0.0) + packHeight; ++i; } zInterlayer = zLow; hasInterlayer = _listLayers[iLayerIndex].HasInterlayer; zLow += hasInterlayer ? interlayerThickness : 0.0; Transform3D swapTransform = Transform3D.Identity; if (_listLayers[iLayerIndex].Swapped) { Matrix4D matRot = new Matrix4D( -1.0, 0.0, 0.0, _parentAnalysis.PalletProperties.Length , 0.0, -1.0, 0.0, _parentAnalysis.PalletProperties.Width , 0.0, 0.0, 1.0, 0.0 , 0.0, 0.0, 0.0, 1.0); swapTransform = new Transform3D(matRot); } // build BoxLayer BoxLayer layer = new BoxLayer(zLow + (hasInterlayer ? interlayerThickness : 0.0), 0); foreach (BoxPosition b in _layer) { layer.Add( new BoxPosition( swapTransform.transform(b.Position + zLow * Vector3D.ZAxis) , HalfAxis.Transform(b.DirectionLength, swapTransform) , HalfAxis.Transform(b.DirectionWidth, swapTransform) ) ); } return layer; }
/// <summary> /// Subtracts a scalar from a matrix. /// </summary> /// <param name="matrix">A <see cref="Matrix4D"/> instance.</param> /// <param name="scalar">A double-precision floating-point number.</param> /// <returns>A new <see cref="Matrix4D"/> instance containing the difference.</returns> public static Matrix4D Subtract(Matrix4D matrix, double scalar) { return new Matrix4D( matrix.M11 - scalar, matrix.M12 - scalar, matrix.M13 - scalar, matrix.M14 - scalar, matrix.M21 - scalar, matrix.M22 - scalar, matrix.M23 - scalar, matrix.M24 - scalar, matrix.M31 - scalar, matrix.M32 - scalar, matrix.M33 - scalar, matrix.M34 - scalar, matrix.M41 - scalar, matrix.M42 - scalar, matrix.M43 - scalar, matrix.M44 - scalar ); }
/// <summary> /// Subtracts a matrix from a matrix and put the result in a third matrix. /// </summary> /// <param name="left">A <see cref="Matrix4D"/> instance to subtract from.</param> /// <param name="right">A <see cref="Matrix4D"/> instance to subtract.</param> /// <param name="result">A <see cref="Matrix4D"/> instance to hold the result.</param> /// <remarks>result[x][y] = left[x][y] - right[x][y]</remarks> public static void Subtract(Matrix4D left, Matrix4D right, ref Matrix4D result) { result.M11 = left.M11 - right.M11; result.M12 = left.M12 - right.M12; result.M13 = left.M13 - right.M13; result.M14 = left.M14 - right.M14; result.M21 = left.M21 - right.M21; result.M22 = left.M22 - right.M22; result.M23 = left.M23 - right.M23; result.M24 = left.M24 - right.M24; result.M31 = left.M31 - right.M31; result.M32 = left.M32 - right.M32; result.M33 = left.M33 - right.M33; result.M34 = left.M34 - right.M34; result.M41 = left.M41 - right.M41; result.M42 = left.M42 - right.M42; result.M43 = left.M43 - right.M43; result.M44 = left.M44 - right.M44; }
/// <summary> /// if box bottom oriented to Z+, reverse box /// </summary> private LayerPosition AdjustLayerPosition(LayerPosition layerPos, bool reflectionX, bool reflectionY) { Vector3D dimensions = Analysis.ContentDimensions; Vector2D containerDims = Analysis.ContainerDimensions; // implement change LayerPosition layerPosTemp = new LayerPosition(layerPos); // apply symetry in X if (reflectionX) { Matrix4D matRot = new Matrix4D( 1.0, 0.0, 0.0, 0.0 , 0.0, -1.0, 0.0, 0.0 , 0.0, 0.0, 1.0, 0.0 , 0.0, 0.0, 0.0, 1.0 ); Vector3D vTranslation = new Vector3D(0.0, containerDims.Y, 0.0); layerPosTemp = ApplyReflection(layerPosTemp, matRot, vTranslation); } // apply symetry in Y if (reflectionY) { Matrix4D matRot = new Matrix4D( -1.0, 0.0, 0.0, 0.0 , 0.0, 1.0, 0.0, 0.0 , 0.0, 0.0, 1.0, 0.0 , 0.0, 0.0, 0.0, 1.0 ); Vector3D vTranslation = new Vector3D(containerDims.X, 0.0, 0.0); layerPosTemp = ApplyReflection(layerPosTemp, matRot, vTranslation); } return layerPosTemp.Adjusted(dimensions); }