/** * divideCrvsByDeltaTan : Curve[] * double -> LinkedList<Plane> * REQUIRES: theta > 0 * ENSURES: divideCrvsByDeltaTan(crvs, theta) returns a linked list of planes * along the curves s.t. there is a plane at every point along * the curve where the change in the tangent vector between * two points is greater than theta. **/ private IEnumerable<Point3d> DivByAngle(Curve crv, double angle) { //initialize parameters double theta = angle; Interval dom = crv.Domain; double stepSize = Math.Abs(dom.Length) * Constants.AbsoluteTolerance * Constants.AbsoluteTolerance; //initialize list List<Point3d> pts = new List<Point3d>(); Continuity c = Continuity.C1_continuous; //initialize data double rover = dom.Min; //steps along the curve by stepSize //Add plane at start point of curve to list Point3d pt = crv.PointAt(rover); pts.Add(pt); //Increment Vector3d prevTan = crv.TangentAt(rover); double oldRover = rover; //stores the previous rover for comparison rover += stepSize; while (rover < dom.Max) { Vector3d currTan = crv.TangentAt(rover); //If there is a discontinuity between the oldRover and rover //then place a point at the discontinuity and update prevTan. double discontinuity; bool isDisc = crv.GetNextDiscontinuity(c, oldRover, rover, out discontinuity); if (isDisc) { pt = crv.PointAt(discontinuity); pts.Add(pt); prevTan = crv.TangentAt(discontinuity); } //If the change in tangent vector is greater than theta, //then drop a target at the rover and update prevTan. double delta = RhinoMath.ToDegrees(Math.Abs(Vector3d.VectorAngle(prevTan, currTan))); if (delta > theta) { pt = crv.PointAt(rover); pts.Add(pt); prevTan = currTan; } //Increment oldRover = rover; rover += stepSize; } //Add target at end point of curve pt = crv.PointAt(dom.Max); pts.Add(pt); return pts; }
/// <summary> /// Computes the fillet arc for a curve filleting operation. /// </summary> /// <param name="curve0">First curve to fillet.</param> /// <param name="curve1">Second curve to fillet.</param> /// <param name="radius">Fillet radius.</param> /// <param name="t0Base">Parameter on curve0 where the fillet ought to start (approximately).</param> /// <param name="t1Base">Parameter on curve1 where the fillet ought to end (approximately).</param> /// <returns>The fillet arc on success, or Arc.Unset on failure.</returns> public static Arc CreateFillet(Curve curve0, Curve curve1, double radius, double t0Base, double t1Base) { Arc arc = Arc.Unset; double t0, t1; Plane plane; if (GetFilletPoints(curve0, curve1, radius, t0Base, t1Base, out t0, out t1, out plane)) { Vector3d radial0 = curve0.PointAt(t0) - plane.Origin; Vector3d radial1 = curve1.PointAt(t1) - plane.Origin; radial0.Unitize(); radial1.Unitize(); double angle = System.Math.Acos(radial0 * radial1); Plane fillet_plane = new Plane(plane.Origin, radial0, radial1); arc = new Arc(fillet_plane, plane.Origin, radius, angle); } return arc; }
public Plane horizFrame(Curve C, double t) { //Create a plane aligned with the world z-axis Vector3d Tangent = C.TangentAt(t); Vector3d Z = Vector3d.ZAxis; Z.Reverse(); Vector3d Perp = Vector3d.CrossProduct(Z, Tangent); Plane frame = new Plane(C.PointAt(t), Tangent, Perp); return frame; }
private LyrebirdCurve GetLBCurve(Curve crv) { LyrebirdCurve lbc = null; List<LyrebirdPoint> points = new List<LyrebirdPoint>(); if (crv.IsLinear()) { // standard linear element points.Add(new LyrebirdPoint(crv.PointAtStart.X, crv.PointAtStart.Y, crv.PointAtStart.Z)); points.Add(new LyrebirdPoint(crv.PointAtEnd.X, crv.PointAtEnd.Y, crv.PointAtEnd.Z)); lbc = new LyrebirdCurve(points, "Line"); } else if (crv.IsCircle()) { crv.Domain = new Interval(0, 1); points.Add(new LyrebirdPoint(crv.PointAtStart.X, crv.PointAtStart.Y, crv.PointAtStart.Z)); points.Add(new LyrebirdPoint(crv.PointAt(0.25).X, crv.PointAt(0.25).Y, crv.PointAt(0.25).Z)); points.Add(new LyrebirdPoint(crv.PointAt(0.5).X, crv.PointAt(0.5).Y, crv.PointAt(0.5).Z)); points.Add(new LyrebirdPoint(crv.PointAt(0.75).X, crv.PointAt(0.75).Y, crv.PointAt(0.75).Z)); points.Add(new LyrebirdPoint(crv.PointAtEnd.X, crv.PointAtEnd.Y, crv.PointAtEnd.Z)); lbc = new LyrebirdCurve(points, "Circle"); } else if (crv.IsArc()) { crv.Domain = new Interval(0, 1); // standard arc element points.Add(new LyrebirdPoint(crv.PointAtStart.X, crv.PointAtStart.Y, crv.PointAtStart.Z)); points.Add(new LyrebirdPoint(crv.PointAt(0.5).X, crv.PointAt(0.5).Y, crv.PointAt(0.5).Z)); points.Add(new LyrebirdPoint(crv.PointAtEnd.X, crv.PointAtEnd.Y, crv.PointAtEnd.Z)); lbc = new LyrebirdCurve(points, "Arc"); } else { // Spline // Old line: if (crv.Degree >= 3) if (crv.Degree == 3) { NurbsCurve nc = crv as NurbsCurve; if (nc != null) { List<LyrebirdPoint> lbPoints = new List<LyrebirdPoint>(); List<double> weights = new List<double>(); List<double> knots = new List<double>(); foreach (ControlPoint cp in nc.Points) { LyrebirdPoint pt = new LyrebirdPoint(cp.Location.X, cp.Location.Y, cp.Location.Z); double weight = cp.Weight; lbPoints.Add(pt); weights.Add(weight); } for (int k = 0; k < nc.Knots.Count; k++) { double knot = nc.Knots[k]; // Add a duplicate knot for the first and last knot in the Rhino curve. // Revit needs 2 more knots than Rhino to define a spline. if (k == 0 || k == nc.Knots.Count - 1) { knots.Add(knot); } knots.Add(knot); } lbc = new LyrebirdCurve(lbPoints, weights, knots, nc.Degree, nc.IsPeriodic) { CurveType = "Spline" }; } } else { const double incr = 1.0 / 100; List<LyrebirdPoint> pts = new List<LyrebirdPoint>(); List<double> weights = new List<double>(); for (int i = 0; i <= 100; i++) { Point3d pt = crv.PointAtNormalizedLength(i * incr); LyrebirdPoint lbp = new LyrebirdPoint(pt.X, pt.Y, pt.Z); weights.Add(1.0); pts.Add(lbp); } lbc = new LyrebirdCurve(pts, "Spline") { Weights = weights, Degree = crv.Degree }; } } return lbc; }
public Mesh MeshLoft(Curve c1, Curve c2, int u, int v) { double[] uList1 = c1.DivideByCount(u, true); double[] uList2 = c2.DivideByCount(u, true); List<Polyline> input1 = new List<Polyline>(); for (int i = 0; i < uList1.Length; i++) { Point3d p1 = c1.PointAt(uList1[i]); Point3d p2 = c2.PointAt(uList2[i]); Vector3d V = p2 - p1; V /= v; Polyline pl = new Polyline(); for (int k = 0; k < v + 1; k++) { pl.Add(p1 + (V * k)); } input1.Add(pl); } return MeshLoft(input1, false, false); }
public Mesh TriangleMeshLoft2(Curve c1, Curve c2, int t1, int t2) { Vector3d v1 = c1.PointAtEnd - c1.PointAtStart; Vector3d v2 = c2.PointAtEnd - c2.PointAtStart; if (Vector3d.VectorAngle(v1, v2) > Math.PI / 2) { c2.Reverse(); } Mesh mesh = new Mesh(); List<Point3d> ps = new List<Point3d>(); int Count = t1 - t2; double[] t01 = c1.DivideByCount(Count, true); double[] t02 = c2.DivideByCount(Count, true); for (int i = t2; i <= t1; i++) { Point3d p1 = c1.PointAt(t01[i - t2]); Point3d p2 = c2.PointAt(t02[i - t2]); Vector3d v = p2 - p1; for (int k = 0; k < i; k++) { double t3 = 0; if (i > 1) { t3 = ((double)k / (double)(i - 1)); } ps.Add(p1 + v * t3); } } if (t2 > 1) { return TriangleMeshFromPoints(ps, t2, t1); } if (t2 == 1) { return TriangleMeshFromPoints(ps); } else return mesh; }
public Mesh TriangleMeshLoft(Curve c1, Curve c2, int t1, int t2) { //t2>t1; Vector3d v1 = c1.PointAtEnd - c1.PointAtStart; Vector3d v2 = c2.PointAtEnd - c2.PointAtStart; if (Vector3d.VectorAngle(v1, v2) > Math.PI / 2) { c2.Reverse(); } List<Point3d> ps = new List<Point3d>(); double[] t0 = c2.DivideByCount(t2 - 1, true); for (int i = 0; i < t0.Length; i++) { ps.Add(c2.PointAt(t0[i])); } for (int i = t2; i < t1; i++) { t0 = c2.DivideByCount(i, true); double[] t01 = c1.DivideByCount(i, true); for (int k = 0; k < t01.Length; k++) { Vector3d v = c1.PointAt(t01[k]) - c2.PointAt(t0[k]); v *= (double)((i - t2 + 1)) / (double)(t1 - t2); ps.Add(c2.PointAt(t0[k]) + v); } } return TriangleMeshFromPoints(ps, t2, t1); }
public Mesh TriangleMeshLoft(Curve c1, Point3d c2, int t) { List<Point3d> ps = new List<Point3d>(); ps.Add(c2); for (int i = 2; i < t + 2; i++) { double[] t1 = c1.DivideByCount(i - 1, true); for (int k = 0; k < t1.Length; k++) { Vector3d v = c1.PointAt(t1[k]) - c2; v *= ((double)i - 1) / (double)t; ps.Add(c2 + v); } } return TriangleMeshFromPoints(ps, t + 1); }
public Mesh MeshSweep1(Curve l, Curve l2, int Count, int Count2) { Polyline ls = new Polyline(); double[] div = l2.DivideByCount(Count2, true); for (int i = 0; i < div.Length; i++) { ls.Add(l2.PointAt(div[i])); } return MeshSweep1(l, ls, Count); }
public void CurveCP(Brep x, Curve y, int V, int U) { int u = bitmap1.Size.Width; int v = bitmap1.Size.Height; Graphics g = Graphics.FromImage(bitmap1); g.FillRectangle(new SolidBrush(Color.White), 0, 0, u, v); System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(Color.Black); float step1 = u / U; float step2 = v / V; for (float i = 25; i < u - 25; i += step1) { for (float j = 25; j < v - 25; j += step2) { double Umin = x.Faces[0].Domain(0).Min; double Umax = x.Faces[0].Domain(0).Max; double Vmin = x.Faces[0].Domain(1).Min; double Vmax = x.Faces[0].Domain(1).Max; Point3d pos = x.Faces[0].PointAt(i / u * (Umax - Umin) + Umin, j / v * (Vmax - Vmin) + Vmin); double t; float R; if (y.ClosestPoint(pos, out t, 200)) { double dis = y.PointAt(t).DistanceTo(pos); dis /= 200; R = (float)(1 / dis * 2); if (R > 40) R = 40; } else { R = 20; } g.FillEllipse(myBrush, i - R, v - j - R, R * 2, R * 2); } } myBrush.Dispose(); g.Dispose(); }
public override BroadRay Directions(int index, int thread, ref Random random, ref Curve Curves, ref double[] DomainPower, ref double Delay, ref Phase_Regime ph, ref int S_ID) { double pos = random.NextDouble(); int i; Interval t = Curves.Domain; double x = random.NextDouble() * (t[1] - t[0]) + t[0]; Point3d P = Curves.PointAt(x); Vector3d f = Curves.TangentAt(x); Vector fore = new Hare.Geometry.Vector(f.X, f.Y, f.Z); double Theta = random.NextDouble() * 2 * System.Math.PI; double Phi = random.NextDouble() * 2 * System.Math.PI; Vector Direction = new Hare.Geometry.Vector(Math.Sin(Theta) * Math.Cos(Phi), Math.Sin(Theta) * Math.Sin(Phi), Math.Cos(Theta)); double cosphi = Hare.Geometry.Hare_math.Dot(Direction, fore); double sinphi = Math.Sqrt(1 - cosphi * cosphi); double tanphi = sinphi/cosphi; double F_r = sinphi * sinphi * Math.Pow((tanphi * tanphi + 1) / (tanphi * tanphi + (1 + tanphi * Math.Tan(delta))), 1.5); double[] power = new double[8]; for (int oct = 0; oct < 8; oct++) power[oct] = DomainPower[oct] * reciprocal_velocity * dLinf * F_r; double[] phase = new double[8]; if (ph == Phase_Regime.Random) for (int o = 0; o < 8; o++) phase[o] = random.Next() * 2 * Math.PI; else for (int o = 0; o < 8; o++) phase[o] = 0 - Delay * Utilities.Numerics.angularFrequency[o]; return new BroadRay(Utilities.PachTools.RPttoHPt(P), Direction, random.Next(), thread, DomainPower, phase, Delay, S_ID); }
public override double[] DirPower(int threadid, int random, Vector Direction, double position, ref Curve Curves, ref double[] DomainPower) { X_Event X = new X_Event(); double[] RayPower = new double[8]; Interval t = Curves.Domain; Point3d P = Curves.PointAt((position/t.Length) + t.Min); Vector3d f = Curves.TangentAt(position); Vector fore = new Hare.Geometry.Vector(f.X, f.Y, f.Z); double cosphi = Hare.Geometry.Hare_math.Dot(Direction, fore); double sinphi = Math.Sqrt(1 - cosphi * cosphi); double tanphi = sinphi / cosphi; double F_r = sinphi * sinphi * Math.Pow((tanphi * tanphi + 1) / (tanphi * tanphi + (1 + tanphi * Math.Tan(delta))), 1.5); for (int oct = 0; oct < 8; oct++) { if (DomainPower[oct] == 0) { RayPower[oct] = 0; } else { RayPower[oct] = DomainPower[oct] * reciprocal_velocity * dLinf * F_r; } } return RayPower; }
public override BroadRay Directions(int index, int thread, ref Random random, ref Curve Curves, ref double[] DomainPower, ref double Delay, ref Phase_Regime ph, ref int S_ID) { double pos = random.NextDouble(); int i; Interval t = Curves.Domain; double x = random.NextDouble() * (t[1] - t[0]) + t[0]; Point3d P = Curves.PointAt(x); double Theta = random.NextDouble() * 2 * System.Math.PI; double Phi = random.NextDouble() * 2 * System.Math.PI; Vector Direction = new Hare.Geometry.Vector(Math.Sin(Theta) * Math.Cos(Phi), Math.Sin(Theta) * Math.Sin(Phi), Math.Cos(Theta)); double[] phase = new double[8]; if (ph == Phase_Regime.Random) for (int o = 0; o < 8; o++) phase[o] = random.Next() * 2 * Math.PI; else for (int o = 0; o < 8; o++) phase[o] = 0 - Delay * Utilities.Numerics.angularFrequency[o]; return new BroadRay(Utilities.PachTools.RPttoHPt(P), Direction, random.Next(), thread, DomainPower, phase, Delay, S_ID); }
private void RunScript(Brep x, Curve y, int V, int U, ref object A) { Graphics g = Graphics.FromImage(bitmap1); g.FillRectangle(new SolidBrush(Color.White), 0, 0, u, v); System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(Color.Black); float step1 = u / U; float step2 = v / V; for (float i = 25; i < u - 25; i += step1) { for (float j = 25; j < v - 25; j += step2) { double Umin = x.Faces[0].Domain(0).Min; double Umax = x.Faces[0].Domain(0).Max; double Vmin = x.Faces[0].Domain(1).Min; double Vmax = x.Faces[0].Domain(1).Max; Point3d pos = x.Faces[0].PointAt(i / u * (Umax - Umin) + Umin, j / v * (Vmax - Vmin) + Vmin); double t; float R; if (y.ClosestPoint(pos, out t, 200)) { double dis = y.PointAt(t).DistanceTo(pos); dis /= 200; R = (float)(1 / dis * 2); // Print(R.ToString()); if (R > 40) R = 40; ; } else { R = 20; } g.FillEllipse(myBrush, i - R, v - j - R, R * 2, R * 2); } } myBrush.Dispose(); str = @"C:\maps\temp1.jpg"; bitmap1.Save(str); Print(str); /////////////////////////////////////////////////////////////////////////////////////////////////////// Mesh[] meshes = Mesh.CreateFromBrep(x, MeshingParameters.Smooth); Mesh M = new Mesh(); foreach (Mesh partialMesh in meshes) { M.Append(partialMesh); } m_shapes.Add(M); Rhino.Display.DisplayMaterial mat = new Rhino.Display.DisplayMaterial(); mat.SetTransparencyTexture(str, true); mat.BackTransparency = 0; m_materials.Clear(); m_materials.Add(mat); }
protected override void SolveInstance(IGH_DataAccess DA) { Rhino.Geometry.Curve rectangle = null; DA.GetData(0, ref rectangle); bool closedBool = rectangle.IsClosed; int spans = rectangle.SpanCount; int degree = rectangle.Degree; List <Rhino.Geometry.Point2d> originalPoints = new List <Point2d>(); List <double> xVals = new List <double>(); List <double> yVals = new List <double>(); if (closedBool != true || spans != 4 || degree != 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input curve is not a closed, linear quadrilateral."); return; } for (int i = 0; i < spans; i++) { Rhino.Geometry.Point3d cornerPoint = rectangle.PointAt(rectangle.SpanDomain(i).Min); Rhino.Geometry.Point2d flattenedCornerPoint = new Rhino.Geometry.Point2d(cornerPoint); originalPoints.Add(flattenedCornerPoint); xVals.Add(flattenedCornerPoint.X); yVals.Add(flattenedCornerPoint.Y); } Rhino.Geometry.LineCurve testCurveA = new Rhino.Geometry.LineCurve(originalPoints[0], originalPoints[2]); Rhino.Geometry.LineCurve testCurveB = new Rhino.Geometry.LineCurve(originalPoints[1], originalPoints[3]); if (testCurveA.GetLength() != testCurveB.GetLength()) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input curve is not orthogonal, results are not guaranteed."); } Rhino.Geometry.Point2d topRightPoint = new Rhino.Geometry.Point2d(xVals.Max(), yVals.Max()); DA.SetData(1, topRightPoint); Rhino.Geometry.Point2d topLeftPoint = new Rhino.Geometry.Point2d(xVals.Min(), yVals.Max()); DA.SetData(2, topLeftPoint); Rhino.Geometry.Point2d bottomLeftPoint = new Rhino.Geometry.Point2d(xVals.Min(), yVals.Min()); DA.SetData(3, bottomLeftPoint); Rhino.Geometry.Point2d bottomRightPoint = new Rhino.Geometry.Point2d(xVals.Max(), yVals.Min()); DA.SetData(4, bottomRightPoint); List <Rhino.Geometry.Point2d> orderedPoints = new List <Point2d>(); orderedPoints.Add(topRightPoint); orderedPoints.Add(topLeftPoint); orderedPoints.Add(bottomLeftPoint); orderedPoints.Add(bottomRightPoint); DA.SetDataList(0, orderedPoints); //TODO: Check for rotation. No warnings will be raised if input is orthogonal rotated object, but corners will not be accurate. }
private double computeBiasHeight(Point3d P, bool biasApicalRegions, Curve boundaryCurve) { double t; boundaryCurve.ClosestPoint(P, out t); double minDist = Utils.Distance(P, boundaryCurve.PointAt(t)); if (biasApicalRegions) foreach (Circle apical in iApicals) { double dist = Utils.Distance(P, apical.Center) - (apical.Radius + 0.1); if (dist < 0.0) dist = 0.0; if (dist < minDist) minDist = dist; } return iInitialCurvingBias * (1.0 - Math.Pow(0.9, minDist * 15.0)); }