internal bool AddCurve(Curve crv, double space, bool forceToOpened) { if (crv.IsClosed && space == 0) { AreaMassProperties area = AreaMassProperties.Compute(crv, AM_Util.FLT_EPSILON); // Pre estimates a common weight int numElements = 1000; double faceArea = area.Area / numElements; if (space == 0) { space = Math.Sqrt(faceArea * 4 / Math.Sqrt(3)); } } if (crv is PolylineCurve) { return(AddPolyline(crv as PolylineCurve, space, forceToOpened)); } else if (crv is PolyCurve) { return(AddPolycurve(crv as PolyCurve, space, forceToOpened)); } else if (crv is ArcCurve) { var nurbs = crv.ToNurbsCurve(); return(AddNurbsCurve(nurbs, space, forceToOpened)); } else if (crv is NurbsCurve) { return(AddNurbsCurve(crv as NurbsCurve, space, forceToOpened)); } return(false); }
protected override void PostDrawObjects(DrawEventArgs e) { List <bool> colorList = new List <bool>(); bool switcher = false; base.PostDrawObjects(e); if (DisplayBreps == null) { return; } for (int i = 0; i < DisplayBreps.Count; i++) { if (i > 0) { for (int j = 1; j < Math.Min(5, i + 1); j++) { Curve[] tempCurve; Point3d[] intPoints; Intersection.BrepBrep(DisplayBreps[i], DisplayBreps[i - j], 0.001, out tempCurve, out intPoints); if (tempCurve.Length != 0) { switcher = !colorList[i - j]; j = 100; } } } e.Display.Draw2dText(i.ToString(), Color.Black, AreaMassProperties.Compute(DisplayBreps[i]).Centroid + new Point3d(0, 0, 1), true); RhinoApp.WriteLine(_colors[switcher ? 1 : 0].ToString()); e.Display.DrawBrepShaded(DisplayBreps[i], new DisplayMaterial(_colors[switcher ? 1 : 0])); colorList.Add(switcher); } }
public static int[] findBottomAndTopBrepFace(Brep brep) { //variables Dictionary <int, double> dicZ = new Dictionary <int, double>(); int iz = 0; //methods foreach (var f in brep.Faces) { //find the center point of each brep face Point3d center = AreaMassProperties.Compute(f.ToBrep()).Centroid; dicZ.Add(iz++, center.Z); } //sort results double minZ = dicZ.OrderBy(z => z.Value).First().Value; int iminZ = dicZ.OrderBy(z => z.Value).First().Key; double maxZ = dicZ.OrderBy(z => z.Value).Last().Value; int imaxZ = dicZ.OrderBy(z => z.Value).Last().Key; //outputs int[] bt = new int[2]; bt[0] = iminZ; //id of the lowest brepface in the brep bt[1] = imaxZ; //id of the top brepface in the brep return(bt); }
public static Curve OffsetBoundary(PanelFrame panelFrame, double dist) { //panelFrame.parameters.cellGap / 2.0 - 1 NurbsCurve boundary = GetPlanarPanelBoundary(panelFrame); AreaMassProperties amp = AreaMassProperties.Compute(boundary); if (amp == null) { return(null); } //RhinoDoc.ActiveDoc.Objects.AddCurve(boundary); Curve[] offsets = boundary.Offset(CaveTools.averagePoint(boundary.Points.Select(x => x.Location).ToList()), panelFrame.localPlane.Normal, dist, 5, CurveOffsetCornerStyle.Sharp); if (offsets == null) { offsets = boundary.Offset(CaveTools.averagePoint(boundary.Points.Select(x => x.Location).ToList()), panelFrame.localPlane.Normal, -(dist), 5, CurveOffsetCornerStyle.Sharp); } AreaMassProperties amp2 = AreaMassProperties.Compute(offsets[0]); if (amp2 == null || amp2.Area > amp.Area) { offsets = boundary.Offset(CaveTools.averagePoint(boundary.Points.Select(x => x.Location).ToList()), panelFrame.localPlane.Normal, -(dist), 5, CurveOffsetCornerStyle.Sharp); } amp2 = AreaMassProperties.Compute(offsets[0]); if (amp2 == null || amp2.Area < 10000) { offsets = boundary.Offset(panelFrame.localPlane, -(dist), 5, CurveOffsetCornerStyle.Sharp); } if (offsets == null) { return(null); } return(offsets[0]); }
private Mesh FindPanelByArea(Plane start, ref Plane end, double xdim, ref double area) { Mesh panel = SelectClosestPanel(CaveTools.splitTwoPlanes(start, end, mesh), orientationPlane); AreaMassProperties amp = AreaMassProperties.Compute(panel); if (amp.Area < 9e6) { return(panel); } int attempt = 10; double dist = xdim / 2; while (attempt > 0) { //adjust plane if (amp.Area > 9e6) { end.Origin = end.Origin + end.Normal * dist; } else { end.Origin = end.Origin - end.Normal * dist; } panel = SelectClosestPanel(CaveTools.splitTwoPlanes(start, end, mesh), orientationPlane); amp = AreaMassProperties.Compute(panel); attempt--; dist = dist / 2; } area = amp.Area; return(panel); }
public static Curve OffsetOut(this Curve curve, double distance, Plane plane, CurveOffsetCornerStyle cornerStyle = CurveOffsetCornerStyle.Sharp) { if (distance == 0) { return(curve); } double original_area = AreaMassProperties.Compute(curve).Area; Curve[] offset_1 = curve.Offset(plane, distance, ObjectModel.Tolerance.Distance, cornerStyle); if (offset_1 != null) { double area_1 = AreaMassProperties.Compute(offset_1[0]).Area; if (area_1 > original_area) { return(offset_1[0]); } else { return(curve.Offset(plane, -distance, ObjectModel.Tolerance.Distance, cornerStyle)[0]); } } else { return(curve.Offset(plane, -distance, ObjectModel.Tolerance.Distance, cornerStyle)[0]); } }
public void SplittingTest() { Rectangle3d rect = new Rectangle3d(Plane.WorldXY, 5000, 1000); Curve Boundary = rect.ToNurbsCurve(); List <Plane> splitPlanes = new List <Plane>(); for (int i = 1; i < 5; i++) { Point3d planeOrigin = new Point3d(i * 500, 0, 0); Plane splitPlane = new Plane(planeOrigin, Vector3d.XAxis); splitPlanes.Add(splitPlane); } List <Curve> splitCurves = Curves.DivideCurve(Boundary, splitPlanes); Assert.Equal <int>(5, splitCurves.Count); Assert.All <Curve>(splitCurves, result => Assert.True(result.IsClosed)); double boundaryArea = AreaMassProperties.Compute(Boundary).Area; double splitAreas = 0; foreach (Curve crv in splitCurves) { double crvArea = AreaMassProperties.Compute(crv).Area; splitAreas += crvArea; } Assert.Equal <double>(Math.Round(boundaryArea, 0), Math.Round(splitAreas, 0)); }
/* * public static bool TryCreateBrepWithBuiltInMethods(pps.PolySurface pb, out Brep brep, SurfaceConverter surfConv, CurveConverter curveConv) * { * if (pb.Surfaces.Count <= 0) * { * brep = null; * return true; * } * brep = null; * try * { * int attempts = 0; * while (attempts < 15) * { * if (pb.Surfaces.Count == 1) * { * var surf = pb.Surfaces.FirstOrDefault(); * brep = GetTrimmedBrep(surf, surfConv, curveConv); * } * else * { * for(int i = 0; i < pb.Surfaces.Count; i++) * { * pps.Surface s = pb.Surfaces[i]; * var subrep = GetTrimmedBrep(s, surfConv, curveConv); * if (!subrep.IsValid) { subrep.Repair(Rhino.RhinoMath.ZeroTolerance); } * if(i == 0) { brep = subrep; } * else * { * //brep = Brep.MergeSurfaces(brep, subrep, Rhino.RhinoMath.ZeroTolerance, * // Rhino.RhinoMath.ZeroTolerance, Point2d.Unset, Point2d.Unset, 0.0, true) ?? * // Brep.MergeSurfaces(brep, subrep, Rhino.RhinoMath.ZeroTolerance, Rhino.RhinoMath.ZeroTolerance) ?? * // Brep.JoinBreps(new List<Brep>() { brep, subrep }, Rhino.RhinoMath.ZeroTolerance).First(); * brep = Brep.MergeBreps(new List<Brep>() { brep, subrep }, Rhino.RhinoMath.ZeroTolerance); * } * } * } * * attempts += 1; * //not doing anymore attempts if this time was successful * if (!brep.IsValid) { brep.Repair(Rhino.RhinoMath.ZeroTolerance); } * if (brep.IsValid) { break; } * } * * if (!brep.IsValid) { brep.Repair(Rhino.RhinoMath.ZeroTolerance); } * return brep.IsValid; * } * catch(Exception e) * { * brep = null; * return false; * } * } */ public static Brep GetEnclosedFacesAsBrep(Brep brep, List <Curve> loops) { List <Brep> faces = new List <Brep>(); foreach (var loop in loops) { AreaMassProperties loopArea = AreaMassProperties.Compute(loop); Point3d loopCenter = loopArea.Centroid; faces.Add(brep.Faces.OrderBy((f) => { AreaMassProperties faceArea = AreaMassProperties.Compute(f.DuplicateFace(false)); return(Point3d.Subtract(loopCenter, faceArea.Centroid).Length); }).First().DuplicateFace(true)); } if (faces.Count == 0) { return(null); } else if (faces.Count == 1) { return(faces.First()); } else { var result = Brep.MergeBreps(faces, Rhino.RhinoMath.ZeroTolerance) ?? faces.First(); return(result.IsValid ? result : faces.First()); } }
private Vector3d findAndUpdateNewAverageNormal()//send some of this out to smaller function? { Vector3d newNormal = new Vector3d(0.0, 0.0, 0.0); double totalArea = AreaMassProperties.Compute(proxyAsMesh).Area; for (int i = 0; i < assignedFaces.Count; i++) { Vector3f normal = partition.controller.rhinoMesh.FaceNormals[assignedFaces[i]]; Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh(); for (int j = 0; j < partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts.Count; j++) { Vector3f position = partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts[j].position; mesh.Vertices.Add(position.X, position.Y, position.Z); } if (partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts.Count == 3) { mesh.Faces.AddFace(0, 1, 2); } else if (partition.controller.wingMesh.faces[assignedFaces[i]].faceVerts.Count == 4) { mesh.Faces.AddFace(0, 1, 2, 3); } double area = AreaMassProperties.Compute(mesh).Area; mesh.Normals.ComputeNormals(); Vector3d areaWeightedNormal = Vector3d.Multiply(area / totalArea, mesh.FaceNormals[0]); newNormal = Vector3d.Add(newNormal, areaWeightedNormal); } return(Vector3d.Divide(newNormal, assignedFaces.Count)); }
// constructor public Block(Brep brp) { this.Brp = brp; AreaMassProperties amp = AreaMassProperties.Compute(brp); this.Center = amp.Centroid; }
public static bool IsInside(this Curve subjectCurve, Curve boundCurve) { double areaTol = Tolerance.Area; Curve[] splitCurves = Curve.CreateBooleanIntersection(subjectCurve, boundCurve, areaTol); List <Polyline> plList = Convert.ToPolylines(splitCurves); if (plList.Count >= 1) //Is this really right?? { Polyline biggest_pl = plList.OrderBy(x => AreaMassProperties.Compute(new PolylineCurve(x.GetControlPoints())).Area).ToList().Last(); double recArea = AreaMassProperties.Compute(subjectCurve).Area; double diff = recArea - AreaMassProperties.Compute(new PolylineCurve(biggest_pl.GetControlPoints())).Area; if (diff < ObjectModel.Tolerance.Garden * recArea) { return(true); } else { return(false); } } else { return(false); } }
public static Point3d ComputeCentroid(Curve ftCurve) { // TODO: lowest point in ftCurve. Point3d centroid = AreaMassProperties.Compute(ftCurve).Centroid; return(centroid); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { //Create class instances ObjectModel.MultiFamily MFH = new ObjectModel.MultiFamily(); //Get Data if (!DA.GetData(0, ref MFH)) { return; } //Calculate (shapeFactor = envelopArea/Atemp). Only works for breps with the same floor geometry on every floor. double envelopArea = AreaMassProperties.Compute(MFH.HouseGeom).Area; Rhino.Geometry.Collections.BrepFaceList faces = MFH.HouseGeom.Faces; double floorArea = 0; foreach (var face in faces) { if (face.NormalAt(0.5, 0.5) == new Vector3d(0, 0, -1)) { floorArea = AreaMassProperties.Compute(face).Area; } ; } double shapefactor = envelopArea / (floorArea * MFH.Floors); //Should be the actual number of floors. //Set data DA.SetData(0, shapefactor); }
/// <summary> /// Gets the area. /// </summary> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override double getArea() { Curve weave = getCurve(new Point3d(0, 0, 0)); AreaMassProperties areaMassProps = Rhino.Geometry.AreaMassProperties.Compute(weave); double curveArea = areaMassProps.Area; return(curveArea); }
private void setFaceArea() { AreaMassProperties mp = AreaMassProperties.Compute(caveFace); if (mp != null) { caveFaceArea = mp.Area; } }
protected override void SolveInstance(IGH_DataAccess DA) { Curve SITE_CRV = null; string adjFilePath = "null"; string geomFilePath = "null"; double rotation = double.NaN; if (!DA.GetData(0, ref SITE_CRV)) { return; } if (!DA.GetData(1, ref adjFilePath)) { return; } if (!DA.GetData(2, ref geomFilePath)) { return; } if (!DA.GetData(3, ref rotation)) { return; } double SITE_AREA = AreaMassProperties.Compute(SITE_CRV).Area; CsvParser csvParserAdj = new CsvParser(adjFilePath); adjMatrixStr = csvParserAdj.readFile(); // list of strings - not fields adjObjLi = csvParserAdj.GetAdjObjLi(adjMatrixStr); // list of adj objs CsvParser csvParserGeom = new CsvParser(geomFilePath); geomSpaceStr = csvParserGeom.readFile(); // list of strings - not fields List <string> geomObjStr = csvParserGeom.GetGeomObjLi(geomSpaceStr, SITE_AREA); // read and normalize (area) the geometry List <string> norGeomObjstr = csvParserGeom.norGeomObjLiStr; List <GeomObj> norGeomObjLi = csvParserGeom.norGeomObjLi; DA.SetDataList(0, adjObjLi); DA.SetDataList(1, geomObjStr); DA.SetDataList(2, norGeomObjstr); GenCBspGeom cbspgeom = new GenCBspGeom(SITE_CRV, adjObjLi, norGeomObjLi, rotation); // class for geom methods cbspgeom.GenerateInitialCurve(); // run the recursions and generate the rotated bbx, reverse rotate bbx curves List <Curve> ResultPolys = cbspgeom.ResultBBxPolys; cbspgeom.ExtractPolyFromSite(); // generate the extracted curves from the site List <Curve> ExtractedCrvs = cbspgeom.ExtractedCrvs; // List<Curve> FPolys = cbspgeom.BSPCrvs; // List<Curve> BBxPolys = cbspgeom.BBxCrvs; DA.SetDataList(3, ResultPolys); DA.SetDataList(4, ExtractedCrvs); // DA.SetDataList(5, BBxPolys); }
// constructor public Building(Polyline outline, double far) { this.Outline = outline; this.FAR = far; AreaMassProperties amp = AreaMassProperties.Compute(outline.ToNurbsCurve()); this.Center = amp.Centroid; this.Structure = new Brep(); }
public static Point3d Centroid(this Curve curve) { if (!curve.IsClosed) { return(Point3d.Unset); } return(AreaMassProperties.Compute(curve).Centroid); }
// cut the area with pri/sec lines public void getSecTowerBase(double density) { // brp of self if (this.SecLns.Count == 0) { return; } Brep[] brp = Brep.CreatePlanarBreps(this.OuterBorder, inter_tol); // ensure no duplicated curves here !important List <Curve> joins = new List <Curve>(); List <Point3d> start = new List <Point3d>(); List <Point3d> end = new List <Point3d>(); foreach (Curve cv in this.SecLns) { if (start.Contains(cv.PointAtStart)) { continue; } if (end.Contains(cv.PointAtEnd)) { continue; } start.Add(cv.PointAtStart); end.Add(cv.PointAtEnd); joins.Add(cv); } Curve[] c = Curve.JoinCurves(joins, inter_tol); double off = density * (this.offsetMax() - 2); Curve[] offset = c[0].Offset(this.Center, Vector3d.ZAxis, off, inter_tol, CurveOffsetCornerStyle.Sharp); if (!offset[0].IsValid) { return; } Curve extended = offset[0].Extend(CurveEnd.Both, extent, CurveExtensionStyle.Line); Brep[] cutted = brp[0].Split(new List <Curve> { extended }, inter_tol); cutted = cutted.Where(brptmp => brptmp != null).ToArray(); if (cutted.Length == 0) { return; } List <double> areas = new List <double>(); List <Brep> parts = new List <Brep>(); foreach (Brep cut in cutted) { AreaMassProperties amp = AreaMassProperties.Compute(cut); areas.Add(amp.Area); parts.Add(cut); } this.TowerS = parts[areas.IndexOf(areas.Min())]; }
List <Point3d> FindCentroid(List <Brep> geometry) { List <Point3d> centroid = new List <Point3d>(); for (int i = 0; i < geometry.Count; i++) { centroid.Add(AreaMassProperties.Compute(geometry[i], false, true, false, false).Centroid); } return(centroid); }
public static double GetArea(this Curve curve) { if (!curve.IsClosed) { return(0); } double area = AreaMassProperties.Compute(curve).Area; return(area); }
//inputs reference protected override void SolveInstance(IGH_DataAccess DA) { Curve LeftEdge = null; DA.GetData(0, ref LeftEdge); Curve RightEdge = null; DA.GetData(1, ref RightEdge); Curve canvasBoundary = null; DA.GetData(2, ref canvasBoundary); //Logics double Distance = 0; double LeftLength = LeftEdge.GetLength(); double RightLength = RightEdge.GetLength(); Point3d LeftMidPoint = LeftEdge.PointAtLength(LeftLength / 2); Point3d RightMidPoint = RightEdge.PointAtLength(RightLength / 2); Line DistanceProjection = new Line(LeftMidPoint, RightMidPoint); Distance = DistanceProjection.ToNurbsCurve().GetLength(); // Canvas Boundary Test var area = AreaMassProperties.Compute(canvasBoundary).Area; if (area != 864) { int width = 36; int height = 24; canvasBoundary = new Rectangle3d(Plane.WorldXY, width, height).ToNurbsCurve(); } else if (area == 864) { Point3d CanvasCenter = canvasBoundary.GetBoundingBox(true).Center; var Vector = new Vector3d(CanvasCenter.X, CanvasCenter.Y, CanvasCenter.Z) * (-1); canvasBoundary.Transform(Transform.Translation(Vector)); } // Assign Output DA.SetData(0, Distance); DA.SetData(1, canvasBoundary); }
public static Mesh MoveBuildingsUp(Mesh mesh, Mesh terrain) { Transform xmoveTerrain; Transform xmoveCentroid; const int UnitBox = 1; const double noIntersection = 0.0; Mesh newMesh = mesh.DuplicateMesh(); try { // first traslation Point3d center = AreaMassProperties.Compute(newMesh).Centroid; Ray3d r = new Ray3d(center, Vector3d.ZAxis); var intersec = Rhino.Geometry.Intersect.Intersection.MeshRay(terrain, r); Point3d pt = r.PointAt(intersec); if (intersec != noIntersection) { Vector3d vecCentroid = new Vector3d(0, 0, pt.Z - center.Z); xmoveCentroid = Transform.Translation(vecCentroid); newMesh.Transform(xmoveCentroid); } // move to terrain BoundingBox BBox = newMesh.GetBoundingBox(true); Mesh meshBox = Mesh.CreateFromBox(BBox, UnitBox, UnitBox, UnitBox); Line[] lines = Rhino.Geometry.Intersect.Intersection.MeshMeshFast(terrain, newMesh); Point3d minBBox = BBox.Min; // dimension double start = minBBox.Z; double end = lines.Min(l => l.From.Z); Vector3d vecTerrain = new Vector3d(0, 0, end - start); xmoveTerrain = Transform.Translation(vecTerrain); } catch { xmoveTerrain = Transform.Translation(Vector3d.Zero); } newMesh.Transform(xmoveTerrain); return(newMesh); }
private Rectangle3d TranslateRect(Point3d pt, Rectangle3d r0) { Vector3d c0 = new Vector3d(AreaMassProperties.Compute(r0.ToNurbsCurve()).Centroid); Vector3d tg = new Vector3d(pt); Vector3d t0 = Vector3d.Subtract(tg, c0); Rectangle3d rNew0 = new Rectangle3d(r0.Plane, r0.Width, r0.Height); rNew0.Transform(Transform.Translation(t0)); return(rNew0); }
public static double[] AreaOf(List <Curve> curves) { UnitSystem currentDocUnits = RhinoDoc.ActiveDoc.ModelUnitSystem; double unitSystemScaler = RhinoMath.UnitScale(currentDocUnits, UnitSystem.Feet); double[] areas = new double[curves.Count()]; for (int i = 0; i < curves.Count(); i++) { areas[i] = Math.Round(AreaMassProperties.Compute(curves[i]).Area *unitSystemScaler *unitSystemScaler, 2); } return(areas); }
private IntersectResult Intersect2Curves(Curve a, Curve b) { int clipperPrecision = 100; IntersectResult result = new IntersectResult(); if (Curve.PlanarCurveCollision(a, b, Plane.WorldXY, 0.001f)) { Clipper clipper = new Clipper(); Path subjectA = CurveToPath(a, clipperPrecision); Path subjectB = CurveToPath(b, clipperPrecision); Paths solution = new Paths(); clipper.AddPath(subjectA, PolyType.ptClip, true); clipper.AddPath(subjectB, PolyType.ptSubject, true); clipper.Execute(ClipType.ctIntersection, solution, PolyFillType.pftNonZero, PolyFillType.pftNonZero); if (solution.Count > 0) { result.intersect = true; PolylineCurve pl = PathToPolyline(solution[0], clipperPrecision); result.unionCurve = pl; Point3d minPoint = pl.GetBoundingBox(false).Min; Point3d maxPoint = pl.GetBoundingBox(false).Max; if (maxPoint.X - minPoint.X > maxPoint.Y - minPoint.Y) { result.reboundingVector = new Vector2d(0, -(maxPoint.Y - minPoint.Y)); if (AreaMassProperties.Compute(a).Centroid.Y > AreaMassProperties.Compute(b).Centroid.Y) { result.reboundingVector.Y *= -1; } } else { result.reboundingVector = new Vector2d(-(maxPoint.X - minPoint.X), 0); if (AreaMassProperties.Compute(a).Centroid.X > AreaMassProperties.Compute(b).Centroid.X) { result.reboundingVector.X *= -1; } } } } else { result.intersect = false; result.reboundingVector = Vector2d.Unset; result.unionCurve = null; } return(result); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <Brep> BrepList = new List <Brep>(); if (!DA.GetDataList <Brep>(0, BrepList)) { return; } var Breps = BrepList.OrderByDescending(item => { return(AreaMassProperties.Compute(item).Area); }).ToList(); DA.SetDataList(0, Breps); }
// either trimextrusion is OK. Just make sure we are getting the right one. public Brep TrimExtrusion(Brep ftPlanar, Brep Extrusion, double tolerance) { Brep[] breps = Extrusion.Split(ftPlanar, tolerance); Point3d centroid0 = AreaMassProperties.Compute(breps[0]).Centroid; Point3d centroid1 = AreaMassProperties.Compute(breps[1]).Centroid; if (centroid0.Z > centroid1.Z) { return(breps[0]); } return(breps[1]); }
//オブジェクトのビューポート内での占有率を返す public void Area() { List <Point3d> vertex = new List <Point3d>(3); //box cornear List <Point3d> vertex_rec = new List <Point3d>(); //viewrec List <Curve> triangle_list = new List <Curve>(); List <Point3d> pos_viewcorner = new List <Point3d>(); pos_viewcorner.AddRange(camera.GetNearRect()); pos_viewcorner.Reverse(2, 2); pos_viewcorner.Add(pos_viewcorner[0]); //それぞれの座標を図面の座標へと変換する for (int i = 0; i < corner.Count; i++) { clientpos.Add(CoordinateTransformation(corner[i])); } for (int i = 0; i < pos_viewcorner.Count; i++) { vertex_rec.Add(CoordinateTransformation(pos_viewcorner[i])); } //面積を求めるために各点から3つ選択してできる三角形をすべて求める for (int i = 0; i < clientpos.Count - 2; i++) { vertex.Clear(); vertex.Add(clientpos[i]); vertex.Add(clientpos[i + 1]); for (int j = i + 2; j < clientpos.Count; j++) { vertex.Add(clientpos[j]); vertex.Add(clientpos[i]); triangle_list.Add(Curve.CreateInterpolatedCurve(vertex, 1)); vertex.RemoveAt(3); vertex.RemoveAt(2); } } enclose_view = Curve.CreateInterpolatedCurve(vertex_rec, 1); //画面の範囲を囲う Curve enclose_box = Curve.CreateBooleanUnion(triangle_list)[0]; //ボックスの見えがかりを囲う enclose_intersect = Curve.CreateBooleanIntersection(enclose_box, enclose_view)[0]; //画面上でボックスの見えている範囲 double area_view = AreaMassProperties.Compute(enclose_view).Area; double area_intersect = AreaMassProperties.Compute(enclose_intersect).Area; double account = area_intersect / area_view * 100; RhinoApp.WriteLine(String.Format("The box accounts for {0}% of viewport", account)); }
//here is where the thinking happens... //DA.GetData vs DA.SetData: protected override void SolveInstance(IGH_DataAccess DA) { ////////// int myMaterial = 0; if (!DA.GetData(0, ref myMaterial)) { return; } List <Surface> mySurfaceList = new List <Surface>(); if (!DA.GetDataList(1, mySurfaceList)) { return; } double myThickness = 0.0; if (!DA.GetData(2, ref myThickness)) { return; } ////////// double myVolumeTotal = 0.0; for (int i = 0; i < mySurfaceList.Count; i++) { AreaMassProperties myArea = AreaMassProperties.Compute(mySurfaceList[i]); double myVolume = myArea.Area * myThickness; myVolumeTotal = +myVolume; } ////////// Code to loop through XML nodes and get MinRad value:- double myDensity = 0.0; string temp = IBIS_XML.SelectSingleNode("IBIS/Mass/Material2[@id= '" + myMaterial + "']").InnerText; myDensity = Convert.ToDouble(temp); ////////// double myMass = 0.0; myMass = myDensity * myVolumeTotal; DA.SetData(0, myMass); ////////// }