// // (C) Copyright 2003-2007 by Autodesk, Inc. // // Permission to use, copy, modify, and distribute this software in // object code form for any purpose and without fee is hereby granted, // provided that the above copyright notice appears in all copies and // that both that copyright notice and the limited warranty and // restricted rights notice below appear in all supporting // documentation. // // AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE // UNINTERRUPTED OR ERROR FREE. // // Use, duplication, or disclosure by the U.S. Government is subject to // restrictions set forth in FAR 52.227-19 (Commercial Computer // Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) // (Rights in Technical Data and Computer Software), as applicable. // using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using Autodesk.Revit.Structural; using Autodesk.Revit.Geometry; namespace Revit.SDK.Samples.ObjectViewer.CS { /// /// utility class provide arithmetic of matrix /// public static class MathUtil { /// /// multiply cross two matrix /// /// left matrix /// right matrix /// result matrix public static XYZ[] MultiCross(XYZ[] m1, XYZ[] m2) { XYZ[] result = new XYZ[3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { switch (j) { case 0: (result[i]).X += (m1[i])[k] * (m2[k])[j]; break; case 1: (result[i]).Y += (m1[i])[k] * (m2[k])[j]; break; case 2: (result[i]).Z += (m1[i])[k] * (m2[k])[j]; break; default: break; } } } } return result; } /// /// subtract two XYZ as Matrix /// /// /// /// public static XYZ SubXYZ(XYZ lhs, XYZ rhs) { double x = lhs.X - rhs.X; double y = lhs.Y - rhs.Y; double z = lhs.Z - rhs.Z; XYZ result = new XYZ(x, y, z); return result; } /// /// Add two XYZ as Matrix /// /// /// /// public static XYZ AddXYZ(XYZ lhs, XYZ rhs) { double x = lhs.X + rhs.X; double y = lhs.Y + rhs.Y; double z = lhs.Z + rhs.Z; XYZ result = new XYZ(x, y, z); return result; } /// /// divide a XYZ by a number /// /// divided XYZ /// number /// result public static XYZ DivideXYZ(XYZ lhs, double rhs) { return new XYZ(lhs.X / rhs, lhs.Y / rhs, lhs.Z / rhs); } /// /// get the coordinates from old coordinate system in the new coordinate system /// /// /// /// public static XYZ GetBasis(XYZ point, Transform transform) { double x = point.X; double y = point.Y; double z = point.Z; double x2; double y2; double z2; //transform basis of the old coordinate system in the new coordinate system XYZ b0 = transform.get_Basis(0); XYZ b1 = transform.get_Basis(1); XYZ b2 = transform.get_Basis(2); XYZ origin = transform.Origin; //transform the origin of the old coordinate system in the new coordinate system x2 = x * b0.X + y * b1.X + z * b2.X + origin.X; y2 = x * b0.Y + y * b1.Y + z * b2.Y + origin.Y; z2 = x * b0.Z + y * b1.Z + z * b2.Z + origin.Z; XYZ newPoint = new XYZ(x2, y2, z2); return newPoint; } /// /// transform a Vector instance to a XYZ instance /// /// transformed Vector /// result XYZ public static XYZ Vector2XYZ(Vector v) { return new XYZ(v.X, v.Y, v.Z); } /// /// transform a XYZ instance to a Vector instance /// /// transformed XYZ /// result Vector public static Vector XYZ2Vector(XYZ pnt) { return new Vector(pnt.X, pnt.Y, pnt.Z); } } }