public void ComputeDesiredNeighbours() { // neighbours interaction if (neighbours.Count != 0) { // define flocking vectors Vector3d alignX = Vector3d.Zero; Vector3d alignY = Vector3d.Zero; Vector3d cohesion = Vector3d.Zero; Vector3d separation = Vector3d.Zero; Vector3d pointer; int sepCount = 0; double distanceSquared; double invNCount = 1.0 / neighbours.Count; // neighbours calculations foreach (AgentPlane neighbour in neighbours) { alignX += neighbour.X; alignY += neighbour.Y; pointer = neighbour.O - O; cohesion += pointer; distanceSquared = O.DistanceToSquared(neighbour.O); if (distanceSquared < agentSim.sepDistSquared) { // separation vector is bigger when closer to another agent separation += -pointer * (agentSim.sepDistSquared - distanceSquared); sepCount++; } } // ............................ alignment behavior alignX *= invNCount; alignY *= invNCount; // updates desired direction // multiplies alignment vector by alignment intensity factor desDirX += agentSim.alignmentIntensity * alignX; desDirY += agentSim.alignmentIntensity * alignY; // ............................ cohesion behavior cohesion *= invNCount; // updates desired position // multiplies cohesion vector by cohesion intensity factor desPos += agentSim.cohesionIntensity * cohesion; // ............................ separation behavior if (sepCount > 0) { separation /= sepCount; } // updates desired position // multiplies separation vector by separation intensity factor desPos += agentSim.separationIntensity * separation; } }
public DataTree <Line> GetDowels(double radius = 0.075, int count = 8) { DataTree <Line> dt = new DataTree <Line>(); for (int i = 0; i < this._nexors.Count; i++) { if (this._nexors[i].isNexor != 0) { var path = new GH_Path(i); Point3d c = (this._nexors[i].endPl0.Origin + this._nexors[i].endPl1.Origin) * 0.5; int dir = (c.DistanceToSquared(this._nexors[i].endPl0.Origin + this._nexors[i].endPl0.ZAxis) < c.DistanceToSquared(this._nexors[i].endPl0.Origin - this._nexors[i].endPl0.ZAxis)) ? -1 : 1; Plane plane = this._nexors[i].endPl0.ChangeOrigin(PlaneUtil.LinePlane(this._nexors[i].pipe.line, this._nexors[i].endPl0)); Circle circle = new Circle(plane, radius); Curve curve = circle.ToNurbsCurve(); curve.DivideByCount(count, true, out Point3d[] pts); foreach (Point3d p in pts) { Line line = new Line(p, this._nexors[i].endPl0.ZAxis * dir * 0.15); dt.Add(line, path); //line.Bake(); } plane = this._nexors[i].endPl1.ChangeOrigin(PlaneUtil.LinePlane(this._nexors[i].pipe.line, this._nexors[i].endPl1)); circle = new Circle(plane, radius); curve = circle.ToNurbsCurve(); curve.DivideByCount(count, true, out Point3d[] pts1); dir = (c.DistanceToSquared(this._nexors[i].endPl1.Origin + this._nexors[i].endPl1.ZAxis) < c.DistanceToSquared(this._nexors[i].endPl1.Origin - this._nexors[i].endPl1.ZAxis)) ? -1 : 1; foreach (Point3d p in pts1) { Line line = new Line(p, this._nexors[i].endPl1.ZAxis * dir * 0.15); dt.Add(line, path); //line.Bake(); } //Rhino.RhinoDoc.ActiveDoc.Objects.AddCircle(circle); } } return(dt); }
double planardsquared(Point3d a, Point3d b) { Point3d tmp1 = new Point3d(a.X, a.Y, 0); Point3d tmp2 = new Point3d(b.X, b.Y, 0); double d = tmp1.DistanceToSquared(tmp2); return(d); }
public void ComputeDesiredToTip(List <Tip> neighbourTips) { // reset desired vector desired = Vector3d.Zero; // if neighbour tips list is zero or null return if (neighbourTips == null || neighbourTips.Count == 0) { return; } Vector3d cohesion = Vector3d.Zero; double nTipCount = 0.0; double distSq, angle; Vector3d toNTip; // search neighbour tips list foreach (Tip nTip in neighbourTips) { distSq = pos.DistanceToSquared(nTip.pos); // if tip in radius if (distSq < cR) { // then if tip in angle of vision //toTip = pos - body.O; // now we use dir //toNTip = nTip.pos - body.O; toNTip = nTip.pos - pos; angle = Vector3d.VectorAngle(dir, toNTip); if (angle < angleOfVis) { // add to cohesion vector and increase counter cohesion += toNTip; nTipCount++; } } } // if found tips number > 0 if (nTipCount > 0) { // average cohesion vector cohesion /= nTipCount; // desired is cohesion desired = cohesion; } }
protected override void SolveInstance(IGH_DataAccess DA) { bbox = new BoundingBox(); crvs.Clear(); pts.Clear(); List <Curve> curves = new List <Curve>(); DA.GetDataList(0, curves); double tolerance = 1; DA.GetData(1, ref tolerance); double ecc = -1; DA.GetData(2, ref ecc); ecc = ecc < 0 ? Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance : ecc; CP.ClosestCurveT cp = new CP.ClosestCurveT(); CP.ClosestCurves(curves, tolerance, ref cp); foreach (Curve c in curves) { bbox.Union(c.GetBoundingBox(false)); } for (int i = 0; i < cp.ID0.Count; i++) { Point3d p0 = cp.L0[i].PointAt(cp.T0[i]); Point3d p1 = cp.L1[i].PointAt(cp.T1[i]); if (p0.DistanceToSquared(p1) <= ecc) { pts.Add(p0); } else { crvs.Add(new Line(p0, p1)); } } DA.SetDataList(0, cp.L0); DA.SetDataList(1, cp.L1); DA.SetDataList(2, cp.ID0); DA.SetDataList(3, cp.ID1); DA.SetDataList(4, cp.T0); DA.SetDataList(5, cp.T1); DA.SetData(6, cp); }
public static List <Point3d> IsPointsCloseToCurve(this Curve C, List <Point3d> P, ref List <int> ID, double T = 0.01) { List <Point3d> cp = new List <Point3d>(); List <int> cpID = new List <int>(); double tolSQ = T * T; BoundingBox bbox = C.GetBoundingBox(false); bbox.Inflate(bbox.Diagonal.Length * 0.01); double t; for (int i = 0; i < P.Count; i++) { //if (bbox.Contains(P[i])) { if (!C.IsClosed) { C.ClosestPoint(P[i], out t); Point3d p = C.PointAt(t); if (p.DistanceToSquared(P[i]) < tolSQ) { cp.Add(P[i]); cpID.Add(i); } } else { C.ClosestPoint(P[i], out t); C.TryGetPlane(out Plane plane); var containment = C.ToNurbsCurve().Contains(P[i], plane, T); if (containment == PointContainment.Inside || containment == PointContainment.Coincident) { cp.Add(P[i]); cpID.Add(i); } } //} } ID = cpID; return(cp); }
void move() { // calculates new position Point3d newPos = pos + vel; newPos = er.M.ClosestPoint(newPos); // kills particle if it has reached a pit - update if not if (Math.Abs(newPos.Z - pos.Z) < 0.01 || pos.DistanceToSquared(newPos) < er.maxSpeed * 0.2) { alive = false; } else { pos = newPos; trail.Add(pos); } }
public static List <Point3d> IsPointsInsideMesh(this Mesh M, List <Point3d> P, ref List <int> ID, double T = 0.01) { List <Point3d> cp = new List <Point3d>(); List <int> cpID = new List <int>(); double tolSQ = T * T; Mesh mesh = M.DuplicateMesh(); if (mesh.SolidOrientation() == -1) { mesh.Flip(true, true, true); } BoundingBox bbox = M.GetBoundingBox(false); bbox.Inflate(bbox.Diagonal.Length * 0.01); for (int i = 0; i < P.Count; i++) { if (mesh.IsClosed) { if (mesh.IsPointInside(P[i], T, false)) { cp.Add(P[i]); cpID.Add(i); } } else { Point3d p = mesh.ClosestPoint(P[i]); if (p.DistanceToSquared(P[i]) < tolSQ) { cp.Add(P[i]); cpID.Add(i); } } } ID = cpID; return(cp); }
public static int ClosestPoint(Point3d P, Point3d[] list) { int num = -1; double num1 = double.MaxValue; for (int i = 0; i < list.Length; i++) { if (list[i] != null && list[i].IsValid) { double num2 = P.DistanceToSquared(list[i]); if (num2 < num1) { num1 = num2; num = i; } } } return(num); }
/// <summary> /// Evenly populate a triangle with points. /// </summary> /// <param name="aPoint">The first point of the triangle in world /// (Cartesian) coordinates.</param> /// <param name="bPoint">The second point of the triangle in world /// (Cartesian) coordinates.</param> /// <param name="cPoint">The third point of the triangle in world /// (Cartesian) coordinates.</param> /// <param name="distance">Rough maximum distance between the points. /// This behaves differently for various geometry type and for /// various circumstances. The distance is never higher and often /// is significantly lower.</param> private static List <Point3d> PopulateTriangle(double distance, Point3d aPoint, Point3d bPoint, Point3d cPoint) { // Compute the density of points on the respective face. var abDistanceSq = aPoint.DistanceToSquared(bPoint); var bcDistanceSq = bPoint.DistanceToSquared(cPoint); var caDistanceSq = cPoint.DistanceToSquared(aPoint); var longestEdgeLen = Math.Sqrt( Math.Max(abDistanceSq, Math.Max(bcDistanceSq, caDistanceSq)) ); // Number of face divisions (points) in each direction. var divisions = Math.Ceiling(longestEdgeLen / distance); var points = new List <Point3d>(Convert.ToInt32(Math.Pow((divisions + 1), 2))); for (var ui = 0; ui < divisions; ui++) { for (var wi = 0; wi < divisions; wi++) { var uNormalized = ui / divisions; var wNormalized = wi / divisions; var vNormalized = 1.0 - uNormalized - wNormalized; if (vNormalized >= 0.0) { var barycentric = new Point3d(uNormalized, vNormalized, wNormalized); var cartesian = BarycentricToCartesian(barycentric, aPoint, bPoint, cPoint); points.Add(cartesian); } } } return(points); }
void SetTypeClosest(IEnumerable <GeometryBase> attractors, double maxDistance) { var points = attractors.Where(a => a is Point).Select(p => (p as Point).Location); var curves = attractors.Where(a => a is Curve).Select(c => (c as Curve)); var pointCloud = new PointCloud(points); foreach (var voxel in GetVoxels().Where(v => v.IsActive)) { Point3d p = voxel.Location.Origin; var closestIndex = pointCloud.ClosestPoint(p); var closestPoint = pointCloud[closestIndex].Location; double minDistance = p.DistanceToSquared(closestPoint); foreach (var curve in curves) { if (curve.ClosestPoint(p, out double t, minDistance)) { minDistance = curve.PointAt(t).DistanceToSquared(p); } } var distance = Sqrt(minDistance); var param = distance / maxDistance; param = Rhino.RhinoMath.Clamp(param, 0.0, 1.0); var typeCount = _typesCount.Max(); var type = (int)(param * typeCount); if (type == typeCount) { type--; } voxel.AttractorDistance = param; voxel.Type = type; } }
public double MinimumDistanceTo(Line testLine, out double paramA, out double paramB) { bool rc = Intersection.LineLine(this, testLine, out double paramA1, out double paramB1, 1e-10, true); Point3d ptA1 = this.PointAt(paramA1); Point3d ptB1 = testLine.PointAt(paramB1); Point3d ptA2 = this.ClosestPoint(ptB1, true, out double paramA2); Point3d ptB2 = testLine.ClosestPoint(ptA1, true, out double paramB2); double dist_1 = ptA1.DistanceToSquared(ptB2); double dist_2 = ptA2.DistanceToSquared(ptB1); if (dist_1 < dist_2) { paramA = paramA1; paramB = paramB2; return(dist_1); } else { paramA = paramA2; paramB = paramB1; return(dist_2); } }
public static List <Curve> IsCurvesInsideMesh(this Mesh M, List <Curve> C, ref List <int> ID, double T = 0.01, bool center = true) { List <Curve> cp = new List <Curve>(); List <int> cpID = new List <int>(); double tolSQ = T * T; Mesh mesh = M.DuplicateMesh(); if (mesh.SolidOrientation() == -1) { mesh.Flip(true, true, true); } BoundingBox bbox = M.GetBoundingBox(false); bbox.Inflate(bbox.Diagonal.Length * 0.01); for (int i = 0; i < C.Count; i++) { Polyline pline; bool flag = C[i].TryGetPolyline(out pline); //if (flag) { List <Point3d> P = center ? new List <Point3d> { pline.CenterPoint() } : pline.ToList(); for (int j = 0; j < P.Count; j++) { if (mesh.IsClosed) { if (mesh.IsPointInside(P[j], T, false)) { cp.Add(C[i]); cpID.Add(i); break; } } else { Point3d p = mesh.ClosestPoint(P[j]); if (p.DistanceToSquared(P[j]) < tolSQ) { cp.Add(C[i]); cpID.Add(i); break; } } } // } } ID = cpID; return(cp); }
void SampleCell(object argumentsObject) { SampleCellArguments arguments = (SampleCellArguments)argumentsObject; Box cell = arguments.cell; int depth = arguments.depth; Random random = new Random(seed + depth); Point3d sample = cell.PointAt(random.NextDouble(), random.NextDouble(), random.NextDouble()); bool valid = true; if (sample.DistanceTo(boundary.ClosestPoint(sample)) < distance / 2) { valid = false; } if (valid) { if (!boundary.IsPointInside(sample, RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, true)) { valid = false; } } if (valid) { foreach (var point in samples) { if (sample.DistanceToSquared(point) < distanceSquared) { valid = false; break; } } } if (valid) { samples.Add(sample); } if (cell.X.Length < cellMinimum) { return; } List <Box> newCells = new List <Box>(); for (double u = 0; u < 1; u += 0.5) { for (double v = 0; v < 1; v += 0.5) { for (double w = 0; w < 1; w += 0.5) { Box newCell = new Box(cell.Plane, new Point3d[] { cell.PointAt(u, v, w), cell.PointAt(u + 0.5, v + 0.5, w + 0.5) }); newCells.Add(newCell); } } } List <Task> tasks = new List <Task>(4); for (int i = newCells.Count - 1; i >= 0; i--) { Box newCell = newCells[random.Next(i)]; newCells.Remove(newCell); SampleCellArguments newArguments = new SampleCellArguments(newCell, depth + 1); if (this.random) { Task task = new Task(new Action <object>(SampleCell), newArguments); tasks.Add(task); task.Start(); } else { SampleCell(newArguments); } } foreach (Task task in tasks) { task.Wait(); } return; }
public Polyline[][] GetSupportStructure(Mesh M, double W1, double W2, Plane[] facePlanes, Plane[] linePlanes, Plane[][] endPlanes, int[][] fe_, int[][] fe, Surface s, Dictionary <int, int> eDict, ref Plane[] ep0, ref Plane[] ep1, ref Plane[] lp2, ref Plane[] lp3) { //double thickness = 1.2; //double heightScale = 2; double thickness = W1; double heightScale = W2 * 2; double extend = 1; bool flip = true; Polyline[][] support = new Polyline[linePlanes.Length][]; ep0 = new Plane[linePlanes.Length]; //Neighbour planes0 ep1 = new Plane[linePlanes.Length]; //Neighbour planes01 Plane[] lp0 = new Plane[linePlanes.Length]; //line planes0 Plane[] lp1 = new Plane[linePlanes.Length]; //line planes1 lp2 = new Plane[linePlanes.Length]; //line planes2 rotated 90 lp3 = new Plane[linePlanes.Length]; //line planes3 rotated 90 for (int i = 0; i < linePlanes.Length; i++) { Line projectionAxis = new Line(linePlanes[i].Origin, linePlanes[i].Origin + linePlanes[i].YAxis); Point3d projectedPt = NGonsCore.MeshUtilSimple.SurfaceRay(s, projectionAxis); //Six sides of each beam lp0[i] = linePlanes[i].MovePlanebyAxis(thickness); lp1[i] = linePlanes[i].MovePlanebyAxis(-thickness); lp2[i] = (new Plane(projectedPt, linePlanes[i].XAxis, linePlanes[i].ZAxis)).MovePlanebyAxis(heightScale); lp3[i] = (new Plane(projectedPt, linePlanes[i].XAxis, linePlanes[i].ZAxis)).MovePlanebyAxis(0); ep0[i] = endPlanes[i][0].MovePlanebyAxis(thickness, linePlanes[i].Origin, 2, flip); ep1[i] = endPlanes[i][1].MovePlanebyAxis(thickness, linePlanes[i].Origin, 2, flip); Plane endPlane0_Offset = endPlanes[i][0].MovePlanebyAxis(thickness * extend, linePlanes[i].Origin, 2, !flip); Plane endPlane1_Offset = endPlanes[i][1].MovePlanebyAxis(thickness * extend, linePlanes[i].Origin, 2, !flip); //Rectangle3d r0 = new Rectangle3d(lp2[i],10,10); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(r0); //First outlines List <Plane> sidePlanes = new List <Plane>() { lp0[i], lp2[i], lp1[i], lp3[i] }; Polyline topOutline = PolylineUtil.PolylineFromPlanes(ep0[i], sidePlanes); Polyline botOutline = PolylineUtil.PolylineFromPlanes(ep1[i], sidePlanes); ep0[i] = new Plane(topOutline.CenterPoint(), topOutline.SegmentAt(0).Direction, topOutline.SegmentAt(1).Direction); ep1[i] = new Plane(botOutline.CenterPoint(), botOutline.SegmentAt(0).Direction, botOutline.SegmentAt(1).Direction); Point3d center = (ep0[i].Origin + ep1[i].Origin) * 0.5; if (center.DistanceToSquared(ep0[i].Origin + ep0[i].ZAxis) < center.DistanceToSquared(ep0[i].Origin)) { ep0[i].Flip(); ep0[i].Rotate(-Math.PI * 0.5, ep0[i].ZAxis); } if (center.DistanceToSquared(ep1[i].Origin + ep1[i].ZAxis) < center.DistanceToSquared(ep1[i].Origin)) { ep1[i].Flip(); ep1[i].Rotate(-Math.PI * 0.5, ep1[i].ZAxis); } // ///if (i == 0) // Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(ep0[i],10,10)); support[i] = new Polyline[] { topOutline, botOutline }; } //Loop each edge Tuple <int, int>[][] efe = M.GetEF_LocalID(M.GetAllNGonEdges(M.GetNGonsTopoBoundaries())); for (int i = 0; i < linePlanes.Length; i++) { //int meshE = eDict[i]; Tuple <int, int>[] edgeFaces = efe[i]; //if edge has two faces go inside their local edges if (edgeFaces.Length == 2) { int e0 = fe_[edgeFaces[0].Item1].Next(edgeFaces[0].Item2); int e1 = fe_[edgeFaces[0].Item1].Prev(edgeFaces[0].Item2); int e2 = fe_[edgeFaces[1].Item1].Next(edgeFaces[1].Item2); int e3 = fe_[edgeFaces[1].Item1].Prev(edgeFaces[1].Item2); if (i == 11) { Line[] lines = PolylineUtil.LoftLine(support[i][0], support[i][1]); Point3d[] pInt = PlaneUtil.LinePlane(lines, linePlanes[e0]); Rectangle3d rec = new Rectangle3d(linePlanes[i], 20, 20); Rectangle3d rec0 = new Rectangle3d(linePlanes[e0], 10, 10); Rectangle3d rec1 = new Rectangle3d(linePlanes[e2], 10, 10); //rec.pl //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(rec); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(rec0); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(rec1); //Current stick intersection //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp0[e0])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp0[e1])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp0[e2])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp0[e3])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp1[e0])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp1[e1])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp1[e2])); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoints(PlaneUtil.LinePlane(lines, lp1[e3])); //Compare with neighbour stick intersection - the 4 points } } } return(support); }
public void CreateCut(int segmentID, Plane jointPlane0, Plane jointPlane1, double length_, ref Panel jointPanel, bool bake = false) //, ref Panel neiPanel,) { { double e = 0; Polyline cut = new Polyline(); Line segment0 = contourNoJoints[0].SegmentAt(segmentID); Line segment1 = contourNoJoints[1].SegmentAt(segmentID); double dist = this.plane.Origin.DistanceTo(segment0.PointAt(0.5)); double length = length_;// * dist * 0.01; //Rhino.RhinoApp.WriteLine(dist.ToString()); //Intersect plate edge line and joint plane offsets Point3d edgePoint00 = PlaneUtil.LinePlane(segment0, jointPlane0); Point3d edgePoint01 = PlaneUtil.LinePlane(segment0, jointPlane1); Point3d edgePoint10 = PlaneUtil.LinePlane(segment1, jointPlane0); Point3d edgePoint11 = PlaneUtil.LinePlane(segment1, jointPlane1); //Get direction of a cut Vector3d v00 = PlaneUtil.PlanePlaneVec(planeOffset0, jointPlane0); Vector3d v01 = PlaneUtil.PlanePlaneVec(planeOffset0, jointPlane1); Vector3d v10 = PlaneUtil.PlanePlaneVec(planeOffset1, jointPlane0); Vector3d v11 = PlaneUtil.PlanePlaneVec(planeOffset1, jointPlane1); //Really f****d up way of checking which direction plane must be offseted for correct cut direction Point3d p0 = mesh.ClosestPoint((segment0.PointAt(0.5) + v00 * 10)); Point3d p1 = mesh.ClosestPoint((segment0.PointAt(0.5) - v00 * 10)); //bool moveFlag = (segment0.PointAt(0.5) + v00*10).DistanceTo(planeOffset0.Origin) < (segment0.PointAt(0.5) - v00*10).DistanceTo(planeOffset0.Origin); bool moveFlag = p0.DistanceToSquared((segment0.PointAt(0.5) + v00 * 10)) < p1.DistanceToSquared((segment0.PointAt(0.5) - v00 * 10)); if (bake) { //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(planeOffset0.Origin); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(segment0.PointAt(0.5) + v00*100); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(segment0.PointAt(0.5) - v00*100); } //Moved Points Point3d innerPoint00 = (moveFlag) ? edgePoint00 + (v00 * length) : edgePoint00 - (v00 * length); Point3d innerPoint01 = (moveFlag) ? edgePoint01 + (v01 * length) : edgePoint01 - (v01 * length); Point3d innerPoint10 = (moveFlag) ? edgePoint10 + (v10 * length) : edgePoint10 - (v10 * length); Point3d innerPoint11 = (moveFlag) ? edgePoint11 + (v11 * length) : edgePoint11 - (v11 * length); Point3d innerPointCenter = (innerPoint00 + innerPoint01 + innerPoint10 + innerPoint11) * 0.25; Plane perpPlane = new Plane(innerPointCenter, jointPlane0.Normal, Vector3d.CrossProduct(planeOffset0.Normal, v00)); innerPoint00 = perpPlane.RayPlane(edgePoint00, v00); innerPoint01 = perpPlane.RayPlane(edgePoint01, v01); innerPoint10 = perpPlane.RayPlane(edgePoint10, v10); innerPoint11 = perpPlane.RayPlane(edgePoint11, v11); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(perpPlane, 50, 50)); //Rhino.RhinoDoc.ActiveDoc.Objects.AddRectangle(new Rectangle3d(jointPlane0, 50, 50)); //Middle points and projection to plane Point3d innerPointMid00 = (moveFlag) ? edgePoint00 + (v00 * length * 0.5) : edgePoint00 - (v00 * length * 0.5); Point3d innerPointMid01 = (moveFlag) ? edgePoint01 + (v01 * length * 0.5) : edgePoint01 - (v01 * length * 0.5); Point3d innerPointMid10 = (moveFlag) ? edgePoint10 + (v10 * length * 0.5) : edgePoint10 - (v10 * length * 0.5); Point3d innerPointMid11 = (moveFlag) ? edgePoint11 + (v11 * length * 0.5) : edgePoint11 - (v11 * length * 0.5); Point3d innerPointMid = (innerPointMid00 + innerPointMid01 + innerPointMid10 + innerPointMid11) * 0.25; Plane perpPlaneMid = new Plane(innerPointMid, jointPlane0.Normal, perpPlane.YAxis); innerPointMid00 = perpPlaneMid.RayPlane(edgePoint00, v00); innerPointMid01 = perpPlaneMid.RayPlane(edgePoint01, v01); innerPointMid10 = perpPlaneMid.RayPlane(edgePoint10, v10); innerPointMid11 = perpPlaneMid.RayPlane(edgePoint11, v11); //It is not closest point because the connection is not perpendicular to two adjacent plates //It might be close to perpendicular but not possible Polyline cut0 = new Polyline(new Point3d[] { edgePoint00, innerPointMid00 + v00 * e, innerPointMid01 + v01 * e, edgePoint01 });//perpPlane.ClosestPoint Polyline cut1 = new Polyline(new Point3d[] { edgePoint10, innerPointMid10 + v10 * e, innerPointMid11 + v11 * e, edgePoint11 }); this.cuts.Add(cut0); this.cuts.Add(cut1); Polyline cutNei0 = new Polyline(new Point3d[] { innerPoint00, innerPointMid00 + v00 * -e, innerPointMid10 + v01 * -e, innerPoint10 });//perpPlane.ClosestPoint Polyline cutNei1 = new Polyline(new Point3d[] { innerPoint01, innerPointMid01 + v10 * -e, innerPointMid11 + v11 * -e, innerPoint11 }); jointPanel.cuts.Add(cutNei0); jointPanel.cuts.Add(cutNei1); contour[0].InsertPolyline(cut0); contour[1].InsertPolyline(cut1); jointPanel.contour[0].InsertPolyline(cutNei0); jointPanel.contour[1].InsertPolyline(cutNei1); if (bake) { Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cut0); Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cut1); } //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cutNei0); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline(cutNei1); }
public void ComputeDesiredNeighbours(List <AgentPlane> neighbours) { // neighbours interaction if (neighbours.Count > 0) { // ............................ alignment behavior // align direction with neighbours Vector3d align = Vector3d.Zero; foreach (AgentPlane neighbour in neighbours) { align += neighbour.X; } align /= neighbours.Count; // updates desired direction // multiplies alignment vector by alignment intensity factor desiredDirection += agentSim.AlignmentStrength * align; // ............................ cohesion behavior Vector3d cohesion = Vector3d.Zero; foreach (AgentPlane neighbour in neighbours) { cohesion += (Vector3d)Point3d.Subtract(neighbour.O, O); } cohesion /= neighbours.Count; // updates desired position // multiplies cohesion vector by cohesion intensity factor desiredPosition += agentSim.CohesionStrength * cohesion; // ............................ separation behavior Vector3d separation = Vector3d.Zero; int sepCount = 0; double sepDistSq = agentSim.PlaneRadius * agentSim.PlaneRadius; double distSq; foreach (AgentPlane neighbour in neighbours) { distSq = O.DistanceToSquared(neighbour.O); if (distSq < sepDistSq) { // separation vector is bigger when closer to another agent separation += (Vector3d)Point3d.Subtract(O, neighbour.O) * (sepDistSq - distSq); sepCount++; } } if (sepCount > 0) { separation /= sepCount; } // updates desired position // multiplies separation vector by separation intensity factor desiredPosition += agentSim.SeparationStrength * separation; } }
public static Tuple <SortedDictionary <int, Polyline>, SortedDictionary <int, Polyline> > SplitCurvesByPlane(this Polyline pline, Plane plane) { //Intersect each segment of curve to get cut parameters List <double> T = new List <double>(); for (int i = 0; i < pline.SegmentCount; i++) { double t; bool flag = Rhino.Geometry.Intersect.Intersection.LinePlane(pline.SegmentAt(i), plane, out t); if (flag) { T.Add(i + t); //Print((i + t).ToString()); } } var TArray = T.ToArray(); Array.Sort(TArray); //Split curve by parameters Curve c = pline.ToNurbsCurve(); Curve[] splitCurves = c.Split(TArray); //Check if curve on which side SortedDictionary <int, Polyline> splitPlines0 = new SortedDictionary <int, Polyline>(); SortedDictionary <int, Polyline> splitPlines1 = new SortedDictionary <int, Polyline>(); Plane planeOffset = new Plane(plane); planeOffset.Translate(plane.ZAxis * 0.01); int key = 0; foreach (Curve sp in splitCurves) { Point3d pt = sp.PointAtNormalizedLength(0.5); Point3d cp0 = plane.ClosestPoint(pt); Point3d cp1 = planeOffset.ClosestPoint(pt); Polyline cutPline; if (sp.TryGetPolyline(out cutPline)) { if (cp0.DistanceToSquared(pt) < cp1.DistanceToSquared(pt)) { splitPlines0.Add(key, cutPline); //Rhino.RhinoDoc.ActiveDoc.Objects.AddPolyline( cutPline); } else { splitPlines1.Add(key, cutPline); } } key++; } return(new Tuple <SortedDictionary <int, Polyline>, SortedDictionary <int, Polyline> >(splitPlines0, splitPlines1)); }