/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static TransformMatrix Invert(this TransformMatrix transform) { double[,] m = transform.Matrix; double[,] mNew = new double[4, 4] { { m[1, 2] * m[2, 3] * m[3, 1] - m[1, 3] * m[2, 2] * m[3, 1] + m[1, 3] * m[2, 1] * m[3, 2] - m[1, 1] * m[2, 3] * m[3, 2] - m[1, 2] * m[2, 1] * m[3, 3] + m[1, 1] * m[2, 2] * m[3, 3], m[0, 3] * m[2, 2] * m[3, 1] - m[0, 2] * m[2, 3] * m[3, 1] - m[0, 3] * m[2, 1] * m[3, 2] + m[0, 1] * m[2, 3] * m[3, 2] + m[0, 2] * m[2, 1] * m[3, 3] - m[0, 1] * m[2, 2] * m[3, 3], m[0, 2] * m[1, 3] * m[3, 1] - m[0, 3] * m[1, 2] * m[3, 1] + m[0, 3] * m[1, 1] * m[3, 2] - m[0, 1] * m[1, 3] * m[3, 2] - m[0, 2] * m[1, 1] * m[3, 3] + m[0, 1] * m[1, 2] * m[3, 3], m[0, 3] * m[1, 2] * m[2, 1] - m[0, 2] * m[1, 3] * m[2, 1] - m[0, 3] * m[1, 1] * m[2, 2] + m[0, 1] * m[1, 3] * m[2, 2] + m[0, 2] * m[1, 1] * m[2, 3] - m[0, 1] * m[1, 2] * m[2, 3] }, { m[1, 3] * m[2, 2] * m[3, 0] - m[1, 2] * m[2, 3] * m[3, 0] - m[1, 3] * m[2, 0] * m[3, 2] + m[1, 0] * m[2, 3] * m[3, 2] + m[1, 2] * m[2, 0] * m[3, 3] - m[1, 0] * m[2, 2] * m[3, 3], m[0, 2] * m[2, 3] * m[3, 0] - m[0, 3] * m[2, 2] * m[3, 0] + m[0, 3] * m[2, 0] * m[3, 2] - m[0, 0] * m[2, 3] * m[3, 2] - m[0, 2] * m[2, 0] * m[3, 3] + m[0, 0] * m[2, 2] * m[3, 3], m[0, 3] * m[1, 2] * m[3, 0] - m[0, 2] * m[1, 3] * m[3, 0] - m[0, 3] * m[1, 0] * m[3, 2] + m[0, 0] * m[1, 3] * m[3, 2] + m[0, 2] * m[1, 0] * m[3, 3] - m[0, 0] * m[1, 2] * m[3, 3], m[0, 2] * m[1, 3] * m[2, 0] - m[0, 3] * m[1, 2] * m[2, 0] + m[0, 3] * m[1, 0] * m[2, 2] - m[0, 0] * m[1, 3] * m[2, 2] - m[0, 2] * m[1, 0] * m[2, 3] + m[0, 0] * m[1, 2] * m[2, 3] }, { m[1, 1] * m[2, 3] * m[3, 0] - m[1, 3] * m[2, 1] * m[3, 0] + m[1, 3] * m[2, 0] * m[3, 1] - m[1, 0] * m[2, 3] * m[3, 1] - m[1, 1] * m[2, 0] * m[3, 3] + m[1, 0] * m[2, 1] * m[3, 3], m[0, 3] * m[2, 1] * m[3, 0] - m[0, 1] * m[2, 3] * m[3, 0] - m[0, 3] * m[2, 0] * m[3, 1] + m[0, 0] * m[2, 3] * m[3, 1] + m[0, 1] * m[2, 0] * m[3, 3] - m[0, 0] * m[2, 1] * m[3, 3], m[0, 1] * m[1, 3] * m[3, 0] - m[0, 3] * m[1, 1] * m[3, 0] + m[0, 3] * m[1, 0] * m[3, 1] - m[0, 0] * m[1, 3] * m[3, 1] - m[0, 1] * m[1, 0] * m[3, 3] + m[0, 0] * m[1, 1] * m[3, 3], m[0, 3] * m[1, 1] * m[2, 0] - m[0, 1] * m[1, 3] * m[2, 0] - m[0, 3] * m[1, 0] * m[2, 1] + m[0, 0] * m[1, 3] * m[2, 1] + m[0, 1] * m[1, 0] * m[2, 3] - m[0, 0] * m[1, 1] * m[2, 3] }, { m[1, 2] * m[2, 1] * m[3, 0] - m[1, 1] * m[2, 2] * m[3, 0] - m[1, 2] * m[2, 0] * m[3, 1] + m[1, 0] * m[2, 2] * m[3, 1] + m[1, 1] * m[2, 0] * m[3, 2] - m[1, 0] * m[2, 1] * m[3, 2], m[0, 1] * m[2, 2] * m[3, 0] - m[0, 2] * m[2, 1] * m[3, 0] + m[0, 2] * m[2, 0] * m[3, 1] - m[0, 0] * m[2, 2] * m[3, 1] - m[0, 1] * m[2, 0] * m[3, 2] + m[0, 0] * m[2, 1] * m[3, 2], m[0, 2] * m[1, 1] * m[3, 0] - m[0, 1] * m[1, 2] * m[3, 0] - m[0, 2] * m[1, 0] * m[3, 1] + m[0, 0] * m[1, 2] * m[3, 1] + m[0, 1] * m[1, 0] * m[3, 2] - m[0, 0] * m[1, 1] * m[3, 2], m[0, 1] * m[1, 2] * m[2, 0] - m[0, 2] * m[1, 1] * m[2, 0] + m[0, 2] * m[1, 0] * m[2, 1] - m[0, 0] * m[1, 2] * m[2, 1] - m[0, 1] * m[1, 0] * m[2, 2] + m[0, 0] * m[1, 1] * m[2, 2] } }; return(new TransformMatrix { Matrix = mNew } / transform.Determinant()); }
/***************************************************/ public static ICurve Transform(this Circle curve, TransformMatrix transform) { if (Math.Abs(transform.Determinant() - 1) <= 1e-6 || transform.IsUniformScaling()) { return new Circle { Centre = curve.Centre.Transform(transform), Radius = (curve.StartPoint() - curve.Centre).Transform(transform).Length(), Normal = curve.Normal.Transform(transform) } } ; else { Reflection.Compute.RecordNote("Transformation is not rigid. Converting into NurbsCurve. May occure change in shape"); return(curve.ToNurbsCurve().Transform(transform)); } }
/***************************************************/ /**** Public Methods - Curves ****/ /***************************************************/ public static ICurve Transform(this Arc curve, TransformMatrix transform) { if (Math.Abs(transform.Determinant() - 1) <= 1e-6 || transform.IsUniformScaling()) { return new Arc { Radius = (curve.StartPoint() - curve.CoordinateSystem.Origin).Transform(transform).Length(), StartAngle = curve.StartAngle, EndAngle = curve.EndAngle, CoordinateSystem = curve.CoordinateSystem.Transform(transform) } } ; else { Reflection.Compute.RecordNote("Transformation is not rigid. Converting into NurbsCurve. May occure change in shape"); return(curve.ToNurbsCurve().Transform(transform)); } }
/***************************************************/ public static ICurve Transform(this Ellipse curve, TransformMatrix transform) { if (Math.Abs(transform.Determinant() - 1) <= 1e-6 || transform.IsUniformScaling()) { return new Ellipse { Centre = curve.Centre.Transform(transform), Axis1 = curve.Axis1.Transform(transform), Axis2 = curve.Axis2.Transform(transform), Radius1 = (curve.Axis1.Normalise() * curve.Radius1).Transform(transform).Length(), Radius2 = (curve.Axis2.Normalise() * curve.Radius2).Transform(transform).Length(), } } ; else { Reflection.Compute.RecordNote("Transformation is not rigid. Converting into NurbsCurve. May occure change in shape"); return(curve.ToNurbsCurve().Transform(transform)); } }