public static List <Polygon3D> ToSAM_Polygon3Ds(this Autodesk.Revit.DB.Face face, double tolerance = Core.Tolerance.Distance) { if (face == null) { return(null); } if (face is PlanarFace) { return(ToSAM_Polygon3Ds((PlanarFace)face, tolerance)); } List <Polygon3D> result = new List <Polygon3D>(); List <Triangle3D> triangle3Ds = face.Triangulate(1)?.ToSAM(tolerance)?.GetTriangles(); foreach (Triangle3D triangle3D in triangle3Ds) { Polygon3D polygon3D = Spatial.Create.Polygon3D(triangle3D); if (polygon3D == null) { continue; } result.Add(polygon3D); } return(result); }
public static Shell ToSAM(this IEnumerable <Polyloop> polyloops) { if (polyloops == null || polyloops.Count() == 0) { return(null); } List <Face3D> face3Ds = new List <Face3D>(); foreach (Polyloop polyloop in polyloops) { Polygon3D polygon3D = polyloop?.ToSAM(); if (polygon3D == null) { continue; } Face3D face3D = new Face3D(polygon3D); if (face3D != null) { face3Ds.Add(face3D); } } if (face3Ds.Count == 0) { return(null); } return(new Shell(face3Ds)); }
IEnumerator BuildMeshes() { yield return(null); for (int i = 0; i < fracturePoints.Count; i++) { if (i != gizmoPolyIndex && gizmoPolyIndex != -1) { continue; } Polygon3D poly = new Polygon3D(fracturePoints[i][0], fracturePoints[i][1], fracturePoints[i][2]); //Polygon3D poly = new Polygon3D(fracturePoints[i]); MeshFilter filt = mc3D.createMesh(poly); for (int j = 3; j < fracturePoints[i].Count; j++) { while (!Input.GetMouseButtonUp(1)) { yield return(null); } Debug.Log("poly " + i + " : add point (" + fracturePoints[i][j].x + ", " + fracturePoints[i][j].y + ", " + fracturePoints[i][j].z + ") number of vertices : " + poly.points.Count + "/" + fracturePoints[i].Count); poly.addPoint(fracturePoints[i][j]); mc3D.updateMesh(poly, filt); yield return(null); } } }
public static List <Polygon3D> ToSAM_Polygon3Ds(this IEnumerable <CurveLoop> curveLoops, double tolerance = Core.Tolerance.Distance) { if (curveLoops == null || curveLoops.Count() == 0) { return(null); } List <Polygon3D> polygon3Ds = new List <Polygon3D>(); foreach (CurveLoop curveLoop in curveLoops) { Polygon3D polygon3D = ToSAM_Polygon3D(curveLoop, tolerance); List <Polygon3D> polygon3Ds_Intersection = Spatial.Query.SelfIntersectionPolygon3Ds(polygon3D, tolerance); if (polygon3Ds_Intersection != null) { polygon3Ds.AddRange(polygon3Ds_Intersection); } else { polygon3Ds.Add(polygon3D); } } return(polygon3Ds); }
public static void FillArrow(Graphics g, int x0, int y0, int x1, int y1, double h, double w) { Segment3D seg = new Segment3D(x0, y0, 0.0D, x1, y1, 0.0D); double len = seg.SegLength(); double x = seg.p1.x - seg.p0.x; double y = seg.p1.y - seg.p0.y; double angle; Vector3D p2; if (len > 0.0D) { angle = -System.Math.Atan2(x, y); p2 = seg.LinearIntarp((len - h) / len); } else { angle = 0.0D; p2 = new Vector3D(seg.p0); p2.y += h; } //g.DrawLine((int)(seg.p0.x + 0.5D), (int)(seg.p0.y + 0.5D), (int)(p2.x + 0.5D), (int)(p2.y + 0.5D)); smat.SetSMat(w, h, 0.0D); rmat.SetRzMat(angle); tmat.SetTMat(p2.x, p2.y, p2.z); Matrix44 mat = smat.MultMat(rmat).MultMat(tmat); Polygon3D arw = triangle.Transform(mat); //g.FillPolygon(new SolidBrush(arw.IxArray(), arw.IyArray(), 3); }
public static TBD.Polygon ToTBD(this Polygon3D polygon3D) { if (polygon3D == null) { return(null); } TBD.Polygon result = new TBD.Polygon(); List <Point3D> point3Ds = polygon3D.GetPoints(); if (point3Ds != null) { foreach (Point3D point3D in point3Ds) { if (point3D == null) { continue; } result.AddCoordinate(System.Convert.ToSingle(point3D.X), System.Convert.ToSingle(point3D.Y), System.Convert.ToSingle(point3D.Z)); } } return(result); }
public static void Add3DPolygon(LocalVectorDataSource source, Projection projection) { // Create 3d polygon style and poses Polygon3DStyleBuilder polygon3DStyleBuilder = new Polygon3DStyleBuilder(); polygon3DStyleBuilder.Color = new Color(51, 51, 255, 255); MapPosVector polygon3DPoses = new MapPosVector(); polygon3DPoses.Add(projection.FromWgs84(new MapPos(24.635930, 59.416659))); polygon3DPoses.Add(projection.FromWgs84(new MapPos(24.642453, 59.411354))); polygon3DPoses.Add(projection.FromWgs84(new MapPos(24.646187, 59.409607))); polygon3DPoses.Add(projection.FromWgs84(new MapPos(24.652667, 59.413123))); polygon3DPoses.Add(projection.FromWgs84(new MapPos(24.650736, 59.416703))); polygon3DPoses.Add(projection.FromWgs84(new MapPos(24.646444, 59.416245))); // Create 3d polygon holes poses MapPosVector holePositions = new MapPosVector(); holePositions.Add(projection.FromWgs84(new MapPos(24.643409, 59.411922))); holePositions.Add(projection.FromWgs84(new MapPos(24.651207, 59.412896))); holePositions.Add(projection.FromWgs84(new MapPos(24.643207, 59.414411))); MapPosVectorVector holes = new MapPosVectorVector(); holes.Add(holePositions); // Add to datasource Polygon3D polygon = new Polygon3D(polygon3DPoses, holes, polygon3DStyleBuilder.BuildStyle(), 150); polygon.SetMetaDataElement("ClickText", new Variant("Polygon 3D")); source.Add(polygon); }
public static TBD.Perimeter ToTBD_Perimeter(this Polygon3D polygon3D) { if (polygon3D == null) { return(null); } TBD.Perimeter result = new TBD.Perimeter(); TBD.Polygon polygon = result.CreateFace(); List <Point3D> point3Ds = polygon3D.GetPoints(); if (point3Ds != null) { foreach (Point3D point3D in point3Ds) { if (point3D == null) { continue; } polygon.AddCoordinate(System.Convert.ToSingle(point3D.X), System.Convert.ToSingle(point3D.Y), System.Convert.ToSingle(point3D.Z)); } } return(result); }
public static void drawQuadEdge3d(Polygon3D q, Color c) { for (int i = 0; i < 4; ++i) { drawLines3D(q.points3d[i], q.points3d[(i + 1) % q.points3d.Length], c, 1.5f); } }
public MeshFilter createMesh(Polygon3D polygon) { GameObject obj = new GameObject("poly"); MeshRenderer rend = obj.AddComponent <MeshRenderer>(); rend.material = Resources.Load <Material>("Opaque"); //rend.material.color = new Color(1, 1, 1, 0.8f); //rend.material.SetFloat("_Mode", 3.0f); //rend.material.color = new Color(1, 1, 1, 0.8f); MeshFilter filt = obj.AddComponent <MeshFilter>(); Mesh mesh = new Mesh(); filt.mesh = mesh; meshes.Add(filt); //obj.transform.localScale = new Vector3(1, 1, -1); obj.transform.position = polygon.barycenter; updateMesh(polygon, filt); obj.SetActive(enabled); return(filt); }
public static List <Polygon3D> Polygon3Ds(this CurtainCell curtainCell) { CurveArrArray curveArrArray = curtainCell?.PlanarizedCurveLoops; if (curveArrArray == null) { return(null); } List <Polygon3D> result = new List <Polygon3D>(); foreach (CurveArray curveArray in curtainCell.PlanarizedCurveLoops) { Polygon3D polygon3D = curveArray?.ToSAM_Polygon3D(); if (polygon3D == null && !polygon3D.IsValid()) { continue; } Geometry.Spatial.Plane plane = polygon3D.GetPlane(); if (plane == null) { continue; } result.Add(polygon3D); } return(result); }
public static Shell ToSAM(this ClosedShell closedShell, double tolerance = Tolerance.Distance) { if (closedShell == null) { return(null); } PolyLoop[] polyLoops = closedShell.PolyLoops; if (polyLoops == null) { return(null); } List <Face3D> face3Ds = new List <Face3D>(); foreach (PolyLoop polyLoop in polyLoops) { Polygon3D polygon3D = polyLoop.ToSAM(tolerance); if (polygon3D == null) { return(null); } face3Ds.Add(new Face3D(polygon3D)); } return(new Shell(face3Ds)); }
public static IOpening ToSAM_Opening(this EnergyAnalysisOpening energyAnalysisOpening, ConvertSettings convertSettings) { if (energyAnalysisOpening == null) { return(null); } IOpening result = convertSettings?.GetObject <IOpening>(energyAnalysisOpening.Id); if (result != null) { return(result); } Polygon3D polygon3D = energyAnalysisOpening.GetPolyloop().ToSAM(); if (polygon3D == null) { return(null); } FamilyInstance familyInstance = Core.Revit.Query.Element(energyAnalysisOpening) as FamilyInstance; if (familyInstance == null) { return(null); } if (Core.Revit.Query.Simplified(familyInstance)) { result = Core.Revit.Query.IJSAMObjects <IOpening>(familyInstance)?.FirstOrDefault(); if (result != null) { return(result); } } OpeningType openingType = ToSAM_OpeningType(familyInstance.Symbol, convertSettings); Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance); if (point3D_Location == null) { return(null); } Face3D face3D = new Face3D(Geometry.Spatial.Create.IClosedPlanar3D(polygon3D, point3D_Location)); if (face3D == null) { return(null); } result = Analytical.Create.Opening(openingType, face3D); result.UpdateParameterSets(familyInstance); convertSettings?.Add(energyAnalysisOpening.Id, result); return(result); }
public static Panel ToSAM(this gbXMLSerializer.Surface surface, double tolerance = Tolerance.MicroDistance) { if (surface == null) { return(null); } Polygon3D polygon3D = surface.PlanarGeometry.ToSAM(tolerance); if (polygon3D == null) { return(null); } PanelType panelType = Query.PanelType(surface.surfaceType); Construction construction = new Construction(surface.Name); Panel result = new Panel(construction, panelType, new Face3D(polygon3D)); Opening[] openings = surface.Opening; if (openings != null) { foreach (Opening opening in openings) { Aperture aperture = opening.ToSAM(tolerance); if (aperture != null) { result.AddAperture(aperture); } } } return(result); }
public void TestPushingOfInSpaceInZDirection() { // polygon which we will be moving Polygon3D t1 = new Polygon3D(new List <Point3D> { t1_1, t1_2, t1_3 }, "t1"); // create static polygon, we will be testing whether there is any pushing or not for this polygone Vector3D shift = (-2 * uX) + (-1 * uY) + (+2 * uZ); Polygon3D t2 = new Polygon3D(new List <Point3D> { t1_1 + shift, t1_2 + shift, t1_3 + shift }, "t2"); // we will be pushing one unit up (in Z coordinate) each time and testing the pusing of Vector3D pushingV = (0 * uX) + (0 * uY) + (1 * uZ); Vector3D expectedV = new Vector3D(0, 0, 0); Vector3D resultV = t1.PushingOf(t2, pushingV); Assert.IsTrue(expectedV.Equals(resultV, MSystem.Tolerance * 100)); // XJB - pushes a bit more by design => increase tolerance pushingV += uZ; resultV = t1.PushingOf(t2, pushingV); Assert.IsTrue(expectedV.Equals(resultV, MSystem.Tolerance * 100)); // XJB - pushes a bit more by design => increase tolerance pushingV += uZ; expectedV += uZ; resultV = t1.PushingOf(t2, pushingV); Assert.IsTrue(expectedV.Equals(resultV, MSystem.Tolerance * 100)); // XJB - pushes a bit more by design => increase tolerance pushingV += uZ; expectedV += uZ; resultV = t1.PushingOf(t2, pushingV); Assert.IsTrue(expectedV.Equals(resultV, MSystem.Tolerance * 100)); // XJB - pushes a bit more by design => increase tolerance }
public void TestConstructorSillyPolygons() { // build square but mix the order of the points Polygon3D p = new Polygon3D(new List <Point3D> { s1_1, s1_3, s1_2, s1_4 }, "p"); }
private static List <Face3D> Profiles_FromElevationProfile(this Wall wall) { if (wall == null) { return(null); } if (!ExporterIFCUtils.HasElevationProfile(wall)) { return(null); } IList <CurveLoop> curveLoops = ExporterIFCUtils.GetElevationProfile(wall); if (curveLoops == null) { return(null); } List <Face3D> result = new List <Face3D>(); foreach (CurveLoop curveLoop in curveLoops) { Polygon3D polygon3D = curveLoop.ToSAM_Polygon3D(); if (polygon3D == null) { continue; } result.Add(new Face3D(polygon3D)); } return(result); }
private void TimeTick(SimulationEvent e) { foreach (StateDB.ActiveRegion region in StateDB.dynamicRegions.Values) { if (region.linkedObject == "") { continue; //don't draw unlinked regions } SimulationObjectProxy obProx = objectProxies[region.linkedObject]; //Calculate new absolute poly for region and send ViewPro event LocationValue lvLoc = (LocationValue)obProx["Location"].GetDataValue(); Vec2D loc = new Vec2D(lvLoc); if (!lvLoc.exists) { return; //possible that the tractor object doesn't exist, so don't show it. } Polygon3D absolutePoly = GetAbsolutePolygon(loc, region.poly.Footprint); absolutePoly.TopZ = region.poly.TopZ; absolutePoly.BottomZ = region.poly.BottomZ; region.referencePoint = loc; region.currentAbsolutePolygon = absolutePoly; this.SendViewProActiveRegionUpdate(region.id, region.isVisible, region.displayColor, absolutePoly); } }
public static ModelVisual3D Representation3D(this XYPolygon Poly, IXYPoint refpoint, double height) { MeshBuilder mb = new MeshBuilder(); var pts = new Point3DCollection(); foreach (var p in Poly.Points) { pts.Add(new Point3D(refpoint.X - p.X, refpoint.Y - p.Y, height)); } // POLYGONS (flat and convex) var poly3D = new Polygon3D(pts); // Transform the polygon to 2D var poly2D = poly3D.Flatten(); // Triangulate var tri = poly2D.Triangulate(); if (tri != null) { // Add the triangle indices with the 3D points mb.Append(pts, tri); } var m = MaterialHelper.CreateMaterial(Colors.DimGray, 0.5); var mv3D = new ModelVisual3D(); mv3D.Content = new GeometryModel3D(mb.ToMesh(), m); return(mv3D); }
public void GetNormal_PlanarPolygon_ReturnsCorrectResult() { var p = new Polygon3D(); p.Points.Add(new Point3D(0, 0, 0)); p.Points.Add(new Point3D(1, 0, 0)); p.Points.Add(new Point3D(1, 1, 0)); p.Points.Add(new Point3D(0, 1, 0)); Assert.AreEqual(new Vector3D(0, 0, 1), p.GetNormal()); }
public Polygon3D Clone() { var res = new Polygon3D(); res.basePoint = basePoint; res.normal = normal; res.vertices = new List <Vector3D>(vertices); return(res); }
public void IsPlanar_PlanarPolygon_ReturnsTrue() { var p = new Polygon3D(); p.Points.Add(new Point3D(0, 0, 0)); p.Points.Add(new Point3D(1, 0, 0)); p.Points.Add(new Point3D(1, 1, 0.76)); p.Points.Add(new Point3D(0, 1, 0.76)); Assert.IsTrue(p.IsPlanar()); }
public void IsPlanar_NotPlanarPolygon_ReturnsFalse() { var p = new Polygon3D(); p.Points.Add(new Point3D(0, 0, 0)); p.Points.Add(new Point3D(1, 0, 0)); p.Points.Add(new Point3D(1, 1, 0)); p.Points.Add(new Point3D(0, 1, 0.3)); Assert.IsFalse(p.IsPlanar()); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="dataAccess"> /// The DA object is used to retrieve from inputs and store in outputs. /// </param> protected override void SolveInstance(IGH_DataAccess dataAccess) { ISAMGeometry sAMGeometry = null; if (!dataAccess.GetData(0, ref sAMGeometry) || sAMGeometry == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } Point3D point3D = sAMGeometry as Point3D; if (point3D != null) { dataAccess.SetData(0, Geometry.Topologic.Convert.ToTopologic(point3D)); return; } ICurve3D curve3D = sAMGeometry as ICurve3D; if (curve3D != null) { dataAccess.SetData(0, Geometry.Topologic.Convert.ToTopologic(curve3D)); return; } Polygon3D polygon3D = sAMGeometry as Polygon3D; if (polygon3D != null) { dataAccess.SetData(0, Geometry.Topologic.Convert.ToTopologic(polygon3D)); return; } Face3D face3D = sAMGeometry as Face3D; if (face3D != null) { dataAccess.SetData(0, Geometry.Topologic.Convert.ToTopologic(face3D)); return; } Shell shell = sAMGeometry as Shell; if (shell != null) { Brep brep = Rhino.Convert.ToRhino(shell); if (brep != null) { dataAccess.SetData(0, brep.ToTopologic(Core.Tolerance.MacroDistance)); return; } } AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Cannot convert geometry"); }
internal static IPolygon2D ConvertTo2D(Polygon3D polygon3D, IMatrix44 lcs) { var pts = polygon3D.Select(pt => { var p = lcs.TransformToLCS(pt); return(new Point(p.X, p.Y)); }); return(new Polygon2D(pts)); }
static protected void CutPolygonByPlanes(Polygon3D polygon, WorldcraftSidePlanes sidePlanes, int iSkipPlaneIndex) { for (int i = 0; i < sidePlanes.Count; i++) { if (i != iSkipPlaneIndex) { sidePlanes[i].plane.ClipPolygon(polygon); } } }
public static Aperture ToSAM(this EnergyAnalysisOpening energyAnalysisOpening, ConvertSettings convertSettings) { if (energyAnalysisOpening == null) { return(null); } Aperture result = convertSettings?.GetObject <Aperture>(energyAnalysisOpening.Id); if (result != null) { return(result); } Polygon3D polygon3D = energyAnalysisOpening.GetPolyloop().ToSAM(); if (polygon3D == null) { return(null); } FamilyInstance familyInstance = Core.Revit.Query.Element(energyAnalysisOpening) as FamilyInstance; if (familyInstance == null) { return(new Aperture(null, polygon3D)); } if (Core.Revit.Query.Simplified(familyInstance)) { result = Core.Revit.Query.IJSAMObjects <Aperture>(familyInstance)?.FirstOrDefault(); if (result != null) { return(result); } } ApertureConstruction apertureConstruction = ToSAM_ApertureConstruction(familyInstance, convertSettings); Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance); if (point3D_Location == null) { return(null); } result = new Aperture(apertureConstruction, polygon3D, point3D_Location); result.UpdateParameterSets(energyAnalysisOpening, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); //result.UpdateParameterSets(familyInstance, ActiveSetting.Setting.GetValue<Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap)); //result.Add(Core.Revit.Query.ParameterSet(familyInstance)); convertSettings?.Add(energyAnalysisOpening.Id, result); return(result); }
/// <summary> /// Calculates the absolute polygon of a region given a new location, /// using the region's reference point and relative polygon /// </summary> /// <param name="location"></param> /// <param name="region"></param> /// <returns></returns> private Polygon3D GetAbsolutePolygon(Vec2D refPoint, Polygon2D relativePolygon) { //Vec2D difference = refPoint.VectorDistanceTo(location); Polygon3D absolute = new Polygon3D(0, 0); foreach (Vec2D vertex in relativePolygon.getVertices()) { absolute.AddVertex(vertex.Add(refPoint)); } return(absolute); }
public DynamicRegion(string id, Polygon3D poly, Vec2D refPoint) { this.id = id; this.poly = poly; this.sensorsBlocked = new List <string>(); this.blockingRegion = false; this.speedMultiplier = 1; this.isVisible = true; this.displayColor = 0; this.referencePoint = refPoint; }
public void Flatten_PlanarPolygon2_ReturnsCorrectResult() { var p = new Polygon3D(); p.Points.Add(new Point3D(0, 0, 4)); p.Points.Add(new Point3D(1, 0, 4)); p.Points.Add(new Point3D(1, 1, 4.01)); p.Points.Add(new Point3D(0, 1, 4.01)); var p2 = p.Flatten(); Assert.AreEqual(p2.Points.Count, 4); var tri = p2.Triangulate(); Assert.AreEqual(6, tri.Count); }
public void Parse(string Input) { double AllX = 0, AllY = 0, AllZ = 0; double X, Y, Z; string[] Arr = Input.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); int Length = Arr.Length; string[] Row; for (int i = 0; i < Length; i++) { if (Arr[i] != "" && Arr[i][0] != '#') switch (Arr[i].Substring(0, 2)) { case "v ": Row = Arr[i].Split(null as string[], StringSplitOptions.RemoveEmptyEntries); Array.Resize(ref Points, ++PLength); X = double.Parse(Row[1], System.Globalization.CultureInfo.InvariantCulture); Y = double.Parse(Row[2], System.Globalization.CultureInfo.InvariantCulture); Z = double.Parse(Row[3], System.Globalization.CultureInfo.InvariantCulture); AllX += X; AllY += Y; AllZ += Z; Points[PLength - 1] = new Math3D.Point3D(X, Y, Z); break; case "f ": Row = Arr[i].Split(' '); string[] Temp; int[] F = new int[3]; for (int k = 1; k <= 3; k++) { Temp = Row[k].Split('/'); F[k - 1] = int.Parse(Temp[0]); } Array.Resize(ref Polygons, ++RLength); Polygons[RLength - 1] = new Polygon3D(F[0], F[1], F[2]); Array.Resize(ref Edges, ELength + 3); ELength += 3; Edges[ELength - 3] = new Edge3D(F[0], F[1]); Edges[ELength - 2] = new Edge3D(F[1], F[2]); Edges[ELength - 1] = new Edge3D(F[2], F[0]); break; } } Origin = new Math3D.Point3D(AllX / PLength, AllY / PLength, AllZ / PLength); }