public static bool IsPerpendicular(XYZ v, XYZ w) { double length = v.GetLength(); double length2 = v.GetLength(); double num = Math.Abs(v.DotProduct(w)); return 1E-09 < length && 1E-09 < length2 && 1E-09 > num; }
//求的相交轴网中与第一根平行的所有轴网 public IList <Grid> GetParallelGrid(IList <Grid> intersectGrids, out int count) { IList <Grid> intersectGridneed = new List <Grid>();//使用方向向量的点积求出与第一根轴网平行的所有轴网 Grid grid_first = intersectGrids.First(); intersectGrids.Remove(grid_first); intersectGridneed.Add(grid_first); Line firstLine = grid_first.Curve as Line;//求出第一条相交线的方向向量 XYZ firstLineDirection = firstLine.Direction; foreach (Grid grid_i in intersectGrids) { Line line_i = grid_i.Curve as Line; XYZ line_i_Direction = line_i.Direction; //double dotProduct = firstLineDirection.DotProduct(line_i_Direction);//点积 //if (dotProduct == 1 || dotProduct == -1) //{ // intersectGridneed.Add(grid_i);//获得所有需要重新命名的轴网 //} XYZ crossXyz = firstLineDirection.CrossProduct(line_i_Direction); //叉积 if (crossXyz.GetLength() > -0.000000000001 && crossXyz.GetLength() < 0.000000000001) //判断条件为E-12 { intersectGridneed.Add(grid_i); //获得所有需要重新命名的轴网 } } count = intersectGridneed.Count; return(intersectGridneed); }
public static XYZ ToUnitVector(XYZ vector, XYZAxle defaultAxle = XYZAxle.X) { if (vector.IsUnitLength()) { return(vector); } else if (vector.GetLength() == 0) { switch (defaultAxle) { case XYZAxle.X: return(new XYZ(1, 0, 0)); case XYZAxle.Y: return(new XYZ(0, 1, 0)); case XYZAxle.Z: return(new XYZ(0, 0, 1)); default: throw new NotImplementedException("未实现07130319"); } } else { return(vector * (1 / vector.GetLength())); } }
/// <summary> /// Return true if the vectors v and w /// are non-zero and perpendicular. /// </summary> bool IsPerpendicular(XYZ v, XYZ w) { double a = v.GetLength(); double b = v.GetLength(); double c = Math.Abs(v.DotProduct(w)); return(_eps < a && _eps < b && _eps > c); // c * c < _eps * a * b }
public XYZ ProjectPointOnPlane(XYZ point) { XYZ xyz = null; double num = this.DistancepointtoPlane(point); bool flag = num < double.Epsilon; XYZ result; if (flag) { result = point; } else { XYZ xyz2 = point + num * this.FaceNormal; XYZ xyz3 = point - num * this.FaceNormal; XYZ xyz4 = xyz2 - this.Origin; XYZ xyz5 = xyz3 - this.Origin; double value = 0.0; double value2 = 0.0; bool flag2 = xyz4.GetLength() < 0.0001; if (flag2) { xyz = xyz2; } else { value = xyz4.DotProduct(this.FaceNormal) / xyz4.GetLength(); } bool flag3 = xyz5.GetLength() < 0.0001; if (flag3) { xyz = xyz3; } else { value2 = xyz5.DotProduct(this.FaceNormal) / xyz5.GetLength(); } bool flag4 = Math.Abs(value) < 1E-05; if (flag4) { xyz = xyz2; } bool flag5 = Math.Abs(value2) < 1E-05; if (flag5) { xyz = xyz3; } result = xyz; } return(result); }
/// <summary> /// 实现了一个线比较的运算符,在XY平面上对线进行排序的时候很有用 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Compare(Line a, Line b) { XYZ pa = a.GetEndPoint(0); XYZ qa = a.GetEndPoint(1); XYZ pb = b.GetEndPoint(0); XYZ qb = b.GetEndPoint(1); XYZ va = qa - pa; XYZ vb = qb - pb; // 在XY平面上比较夹角 double ang_a = Math.Atan2(va.Y, va.X); double ang_b = Math.Atan2(vb.Y, vb.X); int d = Compare(ang_a, ang_b); if (d == 0)// 两条线的角度是一样的 { // Compare distance of undouned line to origin double da = (qa.X * pa.Y - qa.Y * pa.Y) / va.GetLength(); double db = (qb.X * pb.Y - qb.Y * pb.Y) / vb.GetLength(); d = Compare(da, db); if (0 == d) { // Compare distance of start point to origin d = Compare(pa.GetLength(), pb.GetLength()); if (0 == d) { // Compare distance of end point to origin d = Compare(qa.GetLength(), qb.GetLength()); } } } return(d); }
public Result Execute( ExternalCommandData revit, ref string message, ElementSet elements) { UIApplication uiapp = revit.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; using (Transaction tx = new Transaction(doc)) { tx.Start("Create Sloped Slab"); double width = 19.685039400; double length = 59.055118200; double height = 9.84251968503937; XYZ[] pts = new XYZ[] { new XYZ(0.0, 0.0, height), new XYZ(width, 0.0, height), new XYZ(width, length, height), new XYZ(0, length, height) }; CurveArray profile = uiapp.Application.Create.NewCurveArray(); Line line = null; int n = pts.GetLength(0); XYZ q = pts[n - 1]; foreach (XYZ p in pts) { line = Line.CreateBound(q, p); profile.Append(line); q = p; } Level level = new FilteredElementCollector(doc) .OfClass(typeof(Level)) .Where <Element>( e => e.Name.Equals("CreateSlopedSlab")) .FirstOrDefault <Element>() as Level; if (null == level) { level = doc.Create.NewLevel(height); level.Name = "Sloped Slab"; } Floor floor = doc.Create.NewSlab( profile, level, line, 0.5, true); tx.Commit(); } return(Result.Succeeded); }
private Arc CreateArc(XYZ PointStart, XYZ PointEnd, double radius, bool largeSagitta) { XYZ midPointChord = 0.5 * (PointStart + PointEnd); XYZ v = null; if (!(bool)this.GetArcRotationAntiClockWise()) { v = PointEnd - PointStart; } else { v = PointStart - PointEnd; } double d = 0.5 * v.GetLength(); // half chord length // Small and large circle sagitta: // http://www.mathopenref.com/sagitta.html double s = largeSagitta ? radius + Math.Sqrt(radius * radius - d * d) // sagitta large : radius - Math.Sqrt(radius * radius - d * d); // sagitta small var PX = Transform.CreateRotation(XYZ.BasisZ, 0.5 * Math.PI); var PX2 = v.Normalize(); var PX3 = v.Normalize().Multiply(s); XYZ midPointArc = midPointChord + Transform.CreateRotation(XYZ.BasisZ, 0.5 * Math.PI).OfVector(v.Normalize().Multiply(s)); return(Arc.Create(PointEnd, PointStart, midPointArc)); }
private void btn_savedata_Click(object sender, EventArgs e) { byte[] imgdata = System.IO.File.ReadAllBytes(@"c:\v1colorimeter\src\x2displaytest\bin\Debug\temp\12345620160209232604_cropped.bmp"); Bitmap myBitmap = new Bitmap(@"c:\v1colorimeter\src\x2displaytest\bin\Debug\temp\12345620160209232604_cropped.bmp"); int height = myBitmap.Height; int width = myBitmap.Width; double[, ,] rgbstr = new double[width, height, 3]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { rgbstr[i, j, 0] = myBitmap.GetPixel(i, j).R; rgbstr[i, j, 1] = myBitmap.GetPixel(i, j).G; rgbstr[i, j, 2] = myBitmap.GetPixel(i, j).B; } } XYZ = ip.rgb2xyz(rgbstr); double sum = 0; double mean = 0; double w = XYZ.GetLength(0); double h = XYZ.GetLength(1); for (int r = 0; r < w; r++) { for (int c = 0; c < h; c++) { sum += XYZ[r, c, 2]; } } mean = sum / (w * h); }
public List <XYZ> GetWallOpenings(Element wall, double eyeLevel, View3D view) { List <XYZ> somePoints = new List <XYZ>(); Curve c = (wall.Location as LocationCurve).Curve; XYZ wallOrigin = c.GetEndPoint(0); XYZ wallEndPoint = c.GetEndPoint(1); XYZ wallDirection = wallEndPoint - wallOrigin; double wallLength = wallDirection.GetLength(); wallDirection = wallDirection.Normalize(); UV offset = new UV(wallDirection.X, wallDirection.Y); double step_outside = offset.GetLength(); XYZ rayStart = new XYZ(wallOrigin.X - offset.U, wallOrigin.Y - offset.V, eyeLevel); ReferenceIntersector intersector = new ReferenceIntersector(wall.Id, FindReferenceTarget.Face, view); IList <ReferenceWithContext> refs = intersector.Find(rayStart, wallDirection); List <XYZ> pointList = new List <XYZ>(refs.Select <ReferenceWithContext, XYZ>(r => r.GetReference().GlobalPoint)); //TaskDialog.Show("title", pointList.Count.ToString()); if (pointList.Count() >= 4) { pointList.RemoveAt(0); pointList.RemoveAt(0); somePoints.AddRange(pointList); } return(somePoints); }
public PlanarFace Facexanhat(XYZ point, XYZ direction, IList <PlanarFace> listFaces, Transform transform) { PlanarFace planarFace = null; double num = double.MinValue; PLane3D plane3D = new PLane3D(point, direction); foreach (PlanarFace i in listFaces) { XYZ xyz = transform.OfVector(i.FaceNormal); XYZ xyz2 = direction.CrossProduct(xyz); bool check = xyz2.GetLength() > 0.001 || xyz.DotProduct(direction) < 0.0; if (!check) { double num2 = plane3D.DistancepointtoPlane(transform.OfPoint(i.Origin)); bool flag2 = num2 < 0.001; if (!flag2) { bool flag3 = num2 > num; if (flag3) { planarFace = i; num = num2; } } } } return(planarFace); }
public void GetLengthTest() { XYZ xyz = new XYZ(1, 1, 1); double result = Math.Sqrt(3); Assert.Equal(result, xyz.GetLength()); }
public static double PointToFace(XYZ point, PlanarFace face) { XYZ faceNormal = face.FaceNormal; XYZ xyz = point - face.Origin; return(Math.Abs(xyz.DotProduct(faceNormal) / faceNormal.GetLength())); }
static public XYZ Project(this XYZ vector, XYZ vectorV) { double magnitude = Math.Abs(vectorV.GetLength()); XYZ projection = vectorV.Multiply(vector.DotProduct(vectorV) / (magnitude * magnitude)); return(projection); }
public static PlanarFace FurthestFace(PlanarFace face, IList <PlanarFace> listFaces, Transform transform) { PlanarFace result = null; double num = double.MinValue; XYZ xyz = transform.OfVector(face.FaceNormal); XYZ xyz2 = transform.OfPoint(face.Origin); PLane3D plane3DLib = new PLane3D(transform.OfPoint(face.Origin), transform.OfVector(face.FaceNormal)); foreach (PlanarFace planarFace in listFaces) { XYZ source = transform.OfVector(planarFace.FaceNormal); XYZ xyz3 = xyz.CrossProduct(source); bool flag = xyz3.GetLength() > 0.001; if (!flag) { double num2 = plane3DLib.DistanceFromPointToPlane(transform.OfPoint(planarFace.Origin)); bool flag2 = num2 < 0.001; if (!flag2) { bool flag3 = num2 > num; if (flag3) { result = planarFace; num = num2; } } } } return(result); }
protected override void Process(IFCAnyHandle ifcCurve) { base.Process(ifcCurve); IFCAnyHandle pnt = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcCurve, "Pnt", false); if (pnt == null) { return; } IFCAnyHandle dir = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcCurve, "Dir", false); if (dir == null) { return; } XYZ pntXYZ = IFCPoint.ProcessScaledLengthIFCCartesianPoint(pnt); XYZ dirXYZ = IFCUnitUtil.ScaleLength(IFCPoint.ProcessIFCVector(dir)); ParametericScaling = dirXYZ.GetLength(); if (MathUtil.IsAlmostZero(ParametericScaling)) { Importer.TheLog.LogWarning(ifcCurve.StepId, "Line has zero length, ignoring.", false); return; } Curve = Line.CreateUnbound(pntXYZ, dirXYZ / ParametericScaling); }
public List <FamilyInstance> GetFamilyInstances2(Document doc, View view, FamilyInstance firstInstance, FamilyInstance secondInstance, XYZ dimDirection) { List <FamilyInstance> list = new List <FamilyInstance>(); bool flag = firstInstance.Id == secondInstance.Id; List <FamilyInstance> result; if (flag) { list.Add(firstInstance); result = list; } else { LocationPoint locationPoint = firstInstance.Location as LocationPoint; LocationPoint locationPoint2 = secondInstance.Location as LocationPoint; bool flag2 = locationPoint == null || locationPoint2 == null; if (flag2) { result = list; } else { list.Add(firstInstance); list.Add(secondInstance); PLane3D pLane3D = new PLane3D(doc.ActiveView.Origin, doc.ActiveView.ViewDirection); XYZ point1 = pLane3D.ProjectPointOnPlane(locationPoint.Point); XYZ point2 = pLane3D.ProjectPointOnPlane(locationPoint2.Point); //XYZ tranlator = Timdiemthu3(point1,point2); //XYZ direction = (tranlator - point2); XYZ direction = (point1 - point2); FilteredElementCollector filteredElementCollector = new FilteredElementCollector(doc, view.Id); IList <FamilyInstance> list2 = (from x in filteredElementCollector.OfClass(typeof(FamilyInstance)).OfCategory(firstInstance.Category.ToBuiltinCategory()).Cast <FamilyInstance>() where x.Symbol.Name.Contains(firstInstance.Symbol.Name) select x).ToList(); foreach (var item in list2) { if (item.Id != firstInstance.Id && item.Id != secondInstance.Id) { XYZ locationinstance = item.Getlocationofinstacne(); //XYZ tranlatoritem = Timdiemthu3(locationinstance, locationPoint2.Point); //XYZ vector = (pLane3D.ProjectPointOnPlane(tranlatoritem) - point2); XYZ vector = (pLane3D.ProjectPointOnPlane(locationinstance) - point2); if (vector.IsParallel(direction)) { if (vector.GetLength() <= direction.GetLength()) { bool flag3 = vector.DotProduct(direction) != 0; if (flag3) { list.Add(item); } } } } } result = list; } } return(result); }
static ModelCurve MakeLine( Document doc, XYZ p, XYZ q) { // Create plane by the points Line line = Line.CreateBound(p, q); XYZ norm = p.CrossProduct(q); if (norm.GetLength() == 0) { norm = XYZ.BasisZ; } //Plane plane = new Plane( norm, q ); // 2016 Plane plane = Plane.CreateByNormalAndOrigin(norm, q); // 2017 SketchPlane skplane = SketchPlane.Create( doc, plane); // Create line return(doc.FamilyCreate.NewModelCurve( line, skplane)); }
/// <summary> /// Generate axis by offset wall boundary /// </summary> /// <param name="line1"></param> /// <param name="line2"></param> /// <returns></returns> public static Line GenerateAxis(Line line1, Line line2) { Curve baseline = line1.Clone(); Curve targetline = line2.Clone(); if (line1.Length < line2.Length) { baseline = line2.Clone(); targetline = line1.Clone(); } targetline.MakeUnbound(); XYZ midPt = baseline.Evaluate(0.5, true); XYZ midPt_proj = targetline.Project(midPt).XYZPoint; XYZ vec = (midPt_proj - midPt) / 2; double offset = vec.GetLength() / 2.0; //Debug.Print(offset.ToString()); if (offset != 0) { Line axis = Line.CreateBound(baseline.GetEndPoint(0) + vec, baseline.GetEndPoint(1) + vec); return(axis); } else { return(null); } //Line axis = baseline.CreateOffset(offset, vec.Normalize()) as Line; }
void CreateChainWithTwoFixedEnds(ReferencePoint pt1, ReferencePoint pt2, int numX, double springDampening, double springRestLength, double springConstant, double mass) { Particle p; Particle p2; XYZ partXYZ1 = pt1.Position; XYZ partXYZ2 = pt2.Position; XYZ lineVec = partXYZ2 - partXYZ1; double stepSize = lineVec.GetLength() / numX; for (int j = 0; j < numX; j++)//step along curve and evaluate at each step, making sure to thread in the existing fixed parts { //double curveParam = 0; XYZ pointOnLine; if (j == 0) // starting point { p = particleSystem.makeParticle(mass, partXYZ1, true); // make first particle fixed } else if (j > 0 && j < numX - 1) // middle points { pointOnLine = partXYZ1 + lineVec.Normalize() * (j * stepSize); p = particleSystem.makeParticle(mass, pointOnLine, false); // make a new particle along curve at j-th point on line p2 = particleSystem.getParticle(j - 1); particleSystem.makeSpring(p, p2, springRestLength, springConstant, springDampening); //make a new spring and connect it to the last-made point } else //last point - fixed { p = particleSystem.getParticle(j - 1); p2 = particleSystem.makeParticle(mass, partXYZ2, true); // make last particle fixed particleSystem.makeSpring(p, p2, springRestLength, springConstant, springDampening); //make a new spring and connect the j-th point to the fixed point } } }
public static PlanarFace FurthestFace(XYZ point, XYZ direction, IList <PlanarFace> listFaces, Transform transform) { PlanarFace result = null; double num = double.MinValue; PLane3D plane3DLib = new PLane3D(point, direction); foreach (PlanarFace planarFace in listFaces) { XYZ xyz = transform.OfVector(planarFace.FaceNormal); XYZ xyz2 = direction.CrossProduct(xyz); bool flag = xyz2.GetLength() > 0.001 || xyz.DotProduct(direction) < 0.0; if (!flag) { double num2 = plane3DLib.DistanceFromPointToPlane(transform.OfPoint(planarFace.Origin)); bool flag2 = num2 < 0.001; if (!flag2) { bool flag3 = num2 > num; if (flag3) { result = planarFace; num = num2; } } } } return(result); }
public static UV GetUVCoordinate(XYZ targetVec, XYZ vecX, XYZ vecY) { vecX = vecX.Normalize(); vecY = vecY.Normalize(); double len = targetVec.GetLength(); double angle = GetAngle(targetVec, vecX, vecY); return(new UV(Math.Cos(angle) * len, Math.Sin(angle) * len)); }
// Token: 0x06000274 RID: 628 RVA: 0x00010210 File Offset: 0x0000E410 private Solid GetWCSSolid() { XYZ endPoint = this._curve.GetEndPoint(0); XYZ endPoint2 = this._curve.GetEndPoint(1); XYZ xyz = endPoint2 - endPoint; IList<CurveLoop> extrusionProfile = this.GetExtrusionProfile(xyz, endPoint); return GeometryCreationUtilities.CreateExtrusionGeometry(extrusionProfile, xyz, xyz.GetLength()); }
/// <summary> /// Calculate the third point to form a triangle that obein the expression: tan(slope) = 2 * height / base. /// </summary> public static XYZ FormTriangle(double slope, XYZ p0, XYZ p1) { double p2x = (p0.X + p1.X) / 2; double p2y = (p0.Y + p1.Y) / 2; XYZ baseVector = p1.Subtract(p0); double p2z = (slope * baseVector.GetLength()) / 2; return(new XYZ(p2x, p2y, p2z)); }
public Edge(ref Node nodea, ref Node nodeb) { nodeA = nodea; nodeB = nodeb; XYZ a = nodeA.Location.Subtract(nodeB.Location); double b = a.GetLength(); Lenth = Math.Abs(b); }
/// <summary> /// 判断两个非零向量是否垂直 /// </summary> /// <param name="v"></param> /// <param name="w"></param> /// <returns></returns> public static bool IsPerpendicular(XYZ v, XYZ w) { double a = v.GetLength(); double b = w.GetLength(); double c = Math.Abs(v.DotProduct(w)); return(_eps < a && _eps < b && _eps > c); }
/// <summary> /// 取向量在指定方向上的投影长度 /// </summary> /// <param name="vector"></param> /// <param name="sideVector"></param> /// <returns></returns> public static double GetLengthBySide(this XYZ vector, XYZ sideVector) { var v = new XYZ(vector.X, vector.Y, 0); var sv = new XYZ(sideVector.X, sideVector.Y, 0); if (Math.Abs(v.DotProduct(sv)) < AnnotationConstaints.MiniValueForXYZ) { return(0); } return(v.GetLength() * Math.Cos(v.AngleTo(sv))); }
public void CopyElementByVectorClipBoard2() { UIDocument uiDoc = this.ActiveUIDocument; Document doc = uiDoc.Document; ElementId eIdHost = uiDoc.Selection.PickObject(ObjectType.Element, "pick Host").ElementId; Element eHost = doc.GetElement(eIdHost); LocationCurve cur = eHost.Location as LocationCurve; Line lineCur = cur.Curve as Line; XYZ q = lineCur.GetEndPoint(0); XYZ p = lineCur.GetEndPoint(1); XYZ v = p - q; double lengCurLine = v.GetLength(); ElementId eIdRebar = uiDoc.Selection.PickObject(ObjectType.Element, "Pick rebar").ElementId; Element eRebar = doc.GetElement(eIdRebar); List <XYZ> myCoors = new List <XYZ>(); string myTextClipBoard = Clipboard.GetText(); //Split each line in string[] distances = myTextClipBoard.Split(';'); foreach (string distance in distances) { XYZ myPointPlace = (Convert.ToDouble(distance) / lengCurLine) * v; myCoors.Add(myPointPlace); } if (myCoors.Count < 1) { TaskDialog.Show("Empty Data", "ClipBoard không có dữ liệu phù hợp..."); return; } // using transcation (edit DB) using (Transaction myTrans = new Transaction(doc, "CopyElementByCoordinate")) { myTrans.Start(); foreach (XYZ myXYZ in myCoors) { ElementTransformUtils.CopyElement(doc, eIdRebar, myXYZ); } myTrans.Commit(); } }
/// <summary> /// Return a solid corresponding to the volume represented by boundingBoxXYZ. /// </summary> /// <param name="lcs">The local coordinate system of the bounding box; if null, assume the Identity transform.</param> /// <param name="boundingBoxXYZ">The bounding box.</param> /// <param name="solidOptions">The options for creating the solid. Allow null to mean default.</param> /// <returns>A solid of the same size and orientation as boundingBoxXYZ, or null if boundingBoxXYZ is invalid or null.</returns> /// <remarks>We don't do any checking on the input transform, which could have non-uniform scaling and/or mirroring. /// This could potentially lead to unexpected results, which we can examine if and when such cases arise.</remarks> public static Solid CreateSolidFromBoundingBox(Transform lcs, BoundingBoxXYZ boundingBoxXYZ, SolidOptions solidOptions) { // Check that the bounding box is valid. if (boundingBoxXYZ == null || !boundingBoxXYZ.Enabled) { return(null); } try { // Create a transform based on the incoming local coordinate system and the bounding box coordinate system. Transform bboxTransform = (lcs == null) ? boundingBoxXYZ.Transform : lcs.Multiply(boundingBoxXYZ.Transform); XYZ[] profilePts = new XYZ[4]; profilePts[0] = bboxTransform.OfPoint(boundingBoxXYZ.Min); profilePts[1] = bboxTransform.OfPoint(new XYZ(boundingBoxXYZ.Max.X, boundingBoxXYZ.Min.Y, boundingBoxXYZ.Min.Z)); profilePts[2] = bboxTransform.OfPoint(new XYZ(boundingBoxXYZ.Max.X, boundingBoxXYZ.Max.Y, boundingBoxXYZ.Min.Z)); profilePts[3] = bboxTransform.OfPoint(new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Max.Y, boundingBoxXYZ.Min.Z)); XYZ upperRightXYZ = bboxTransform.OfPoint(boundingBoxXYZ.Max); // If we assumed that the transforms had no scaling, // then we could simply take boundingBoxXYZ.Max.Z - boundingBoxXYZ.Min.Z. // This code removes that assumption. XYZ origExtrusionVector = new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Min.Y, boundingBoxXYZ.Max.Z) - boundingBoxXYZ.Min; XYZ extrusionVector = bboxTransform.OfVector(origExtrusionVector); double extrusionDistance = extrusionVector.GetLength(); XYZ extrusionDirection = extrusionVector.Normalize(); CurveLoop baseLoop = new CurveLoop(); for (int ii = 0; ii < 4; ii++) { baseLoop.Append(Line.CreateBound(profilePts[ii], profilePts[(ii + 1) % 4])); } IList <CurveLoop> baseLoops = new List <CurveLoop>(); baseLoops.Add(baseLoop); if (solidOptions == null) { return(GeometryCreationUtilities.CreateExtrusionGeometry(baseLoops, extrusionDirection, extrusionDistance)); } else { return(GeometryCreationUtilities.CreateExtrusionGeometry(baseLoops, extrusionDirection, extrusionDistance, solidOptions)); } } catch { return(null); } }
static public XYZ Project(this XYZ point, Plane plane) { XYZ v = plane.Origin - point; XYZ normal = plane.Normal; double magnitude = Math.Abs(normal.GetLength()); XYZ vp = normal.Multiply(v.DotProduct(normal) / (magnitude * magnitude)); XYZ projection = point + vp; return(projection); }
/// <summary> /// Create model lines representing a closed /// planar loop in the given sketch plane. /// </summary> static void DrawModelLineLoop( SketchPlane sketchPlane, XYZ[] corners) { Autodesk.Revit.Creation.Document factory = sketchPlane.Document.Create; int n = corners.GetLength( 0 ); for( int i = 0; i < n; ++i ) { int j = 0 == i ? n - 1 : i - 1; factory.NewModelCurve( Line.CreateBound( corners[j], corners[i] ), sketchPlane ); } }
public Result Execute( ExternalCommandData revit, ref string message, ElementSet elements) { UIApplication uiapp = revit.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; using( Transaction tx = new Transaction( doc ) ) { tx.Start( "Create Sloped Slab" ); double width = 19.685039400; double length = 59.055118200; double height = 9.84251968503937; XYZ[] pts = new XYZ[] { new XYZ( 0.0, 0.0, height ), new XYZ( width, 0.0, height ), new XYZ( width, length, height ), new XYZ( 0, length, height ) }; CurveArray profile = uiapp.Application.Create.NewCurveArray(); Line line = null; int n = pts.GetLength( 0 ); XYZ q = pts[n - 1]; foreach( XYZ p in pts ) { line = Line.CreateBound( q, p ); profile.Append( line ); q = p; } Level level = new FilteredElementCollector( doc ) .OfClass( typeof( Level ) ) .Where<Element>( e => e.Name.Equals( "CreateSlopedSlab" ) ) .FirstOrDefault<Element>() as Level; if( null == level ) { level = doc.Create.NewLevel( height ); level.Name = "Sloped Slab"; } Floor floor = doc.Create.NewSlab( profile, level, line, 0.5, true ); tx.Commit(); } return Result.Succeeded; }
public static void ToSphericalCoordinates(XYZ input, out double r, out double theta, out double phi) { // set length r = input.GetLength(); // if the length is too small the angles will be degenerate, just set them as 0 if (Math.Abs(r) < System.Double.Epsilon) { theta = 0; phi = 0; return; } // get the length of the projection on the xy plane var rInXYPlane = (new XYZ(input.X, input.Y, 0)).GetLength(); // if projected length is 0, xyz is pointing up, down, or is origin if (Math.Abs(rInXYPlane) < System.Double.Epsilon) { // this should have already been detected when r is 0, but check anyway if (Math.Abs(input.Z) < System.Double.Epsilon) { theta = 0; phi = 0; return; } else // determine whether vector is above or below - if above phi is 0 { theta = 0; phi = input.Z > 0 ? 0 : Math.PI; return; } } // if x is 0, this indicates vector is at 90 or 270 if (Math.Abs(input.X) < System.Double.Epsilon) { theta = input.Y > 0 ? Math.PI / 2 : 3 * Math.PI / 2; } else { theta = Math.Atan(input.Y / input.X); } // phew... phi = Math.Acos(input.Z / r); }