public static void Restore(out IParametricCurve2d curve, BinaryReader reader) { curve = null; int nType = reader.ReadInt32(); if (nType == 1) { Segment2d segment = new Segment2d(); Restore(ref segment, reader); curve = segment; } else if (nType == 2) { Circle2d circle = new Circle2d(Vector2D.Zero, 1.0); Restore(ref circle, reader); curve = circle; } else if (nType == 3) { Arc2d arc = new Arc2d(Vector2D.Zero, 1.0, 0, 1); Restore(ref arc, reader); curve = arc; } else if (nType == 100) { ParametricCurveSequence2 seq = new ParametricCurveSequence2(); Restore(ref seq, reader); curve = seq; } else { throw new Exception("gSerialization.Restore: IParametricCurve2D : unknown curve type " + nType.ToString()); } }
Arc2d Get_arc(int i) { Arc a = (i == 0) ? arc1 : arc2; double start_deg = a.AngleStartR * math.MathUtil.Rad2Deg; double end_deg = a.AngleEndR * math.MathUtil.Rad2Deg; if (a.PositiveRotation == true) { double tmp = start_deg; start_deg = end_deg; end_deg = tmp; } Arc2d arc = new Arc2d(a.Center, a.Radius, start_deg, end_deg); // [RMS] code above does not preserve CW/CCW of arcs. // It would be better to fix that. But for now, just check if // we preserved start and end points, and if not reverse curves. if (i == 0 && arc.SampleT(0.0).DistanceSquared(Point1) > math.MathUtil.ZeroTolerance) { arc.Reverse(); } if (i == 1 && arc.SampleT(1.0).DistanceSquared(Point2) > math.MathUtil.ZeroTolerance) { arc.Reverse(); } return(arc); }
public CircleG(int id, Arc2d arc, int pt1, int pt2, int idpt3, out PointG pt3) { Id = id; P1 = pt1; P2 = pt2; pt3 = new PointG(arc.Center, idpt3); P3 = idpt3; }
public static void Restore(ref Arc2d arc, BinaryReader reader) { arc.Center.x = reader.ReadDouble(); arc.Center.y = reader.ReadDouble(); arc.Radius = reader.ReadDouble(); arc.AngleStartDeg = reader.ReadDouble(); arc.AngleEndDeg = reader.ReadDouble(); arc.IsReversed = reader.ReadBoolean(); }
public static void Store(Arc2d arc, BinaryWriter writer) { writer.Write(arc.Center.x); writer.Write(arc.Center.y); writer.Write(arc.Radius); writer.Write(arc.AngleStartDeg); writer.Write(arc.AngleEndDeg); writer.Write(arc.IsReversed); }
public static Arc ToArc(this Arc2d arc2d) { XYZ center = arc2d.Center.ToXYZ(); double radius = arc2d.Radius; double AngleStartDeg = (Math.PI / 180) * arc2d.AngleStartDeg; double AngleEndDeg = (Math.PI / 180) * arc2d.AngleEndDeg; XYZ xAxis = new XYZ(1, 0, 0); XYZ yAxis = new XYZ(0, 1, 0); return(Arc.Create(center, radius, AngleStartDeg, AngleEndDeg, xAxis, yAxis)); }
public static void test_svg() { Polygon2d poly = Polygon2d.MakeCircle(100.0f, 10); PolyLine2d pline = new PolyLine2d(); pline.AppendVertex(Vector2d.Zero); pline.AppendVertex(200 * Vector2d.AxisX); pline.AppendVertex(200 * Vector2d.One); Circle2d circ = new Circle2d(33 * Vector2d.One, 25); Segment2d seg = new Segment2d(Vector2d.Zero, -50 * Vector2d.AxisY); SVGWriter writer = new SVGWriter(); writer.AddPolygon(poly, SVGWriter.Style.Filled("lime", "black", 0.25f)); writer.AddPolyline(pline, SVGWriter.Style.Outline("orange", 2.0f)); writer.AddCircle(circ, SVGWriter.Style.Filled("yellow", "red", 5.0f)); writer.AddLine(seg, SVGWriter.Style.Outline("blue", 10.0f)); int astep = 29; Vector2d c = new Vector2d(-200, 100); for (int k = 1; k <= 12; ++k) { Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, 0, k * astep); writer.AddArc(arc); writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f)); } c.y += 50; for (int k = 1; k <= 12; ++k) { Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, k * astep, (k + 5) * astep); writer.AddArc(arc); writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f)); } c.y += 50; for (int k = 1; k <= 12; ++k) { Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, k * astep, (k + 10) * astep); writer.AddArc(arc); writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f)); } c.y += 50; for (int k = 1; k <= 12; ++k) { Arc2d arc = new Arc2d(c + k * 45 * Vector2d.AxisX, 20, k * astep, (k + 10) * astep); arc.Reverse(); writer.AddArc(arc); writer.AddBox(arc.Bounds, SVGWriter.Style.Outline("red", 0.5f)); } writer.Write(TestUtil.GetTestOutputPath("test.svg")); }
void checkArc(Arc2d a) { Vector2d d1, d2; d1 = u.getTangentVec(a.Evaluator); d2 = u.getTangentVec(a.Evaluator, 0.15); double a1 = d1.AngleTo(u.createVector2d(-1, -1)), a2 = d2.AngleTo(u.createVector2d(-1, -1)); if (a2 - a1 < 0) { ang = -ang; } }
public void direct(Entity prev) { if (prev.ent.Type != ObjectTypeEnum.kSketchArcObject) { return; } Arc2d arc = (prev.ent as SketchArc).Geometry; Curve2dEvaluator ev = arc.Evaluator; double[] par = u.getParam(ev, prev.endPt.Geometry); double[] o = { }; ev.GetTangent(ref par, ref o); dir = u.createVector2d(o[0], o[1]); if (prev.t == entTypes.Arc && !(prev as ArcInv).clockwise) { dir.ScaleBy(-1); } }
/// <summary> /// This is a utility function that returns the set of border points, which /// is useful when we use a roundrect as a UI element and want the border /// </summary> public Vector3D[] GetBorderLoop() { int corner_v = 0; for (int k = 0; k < 4; ++k) { if (((int)SharpCorners & (1 << k)) != 0) { corner_v += 1; } else { corner_v += CornerSteps; } } float innerW = Width - 2 * Radius; float innerH = Height - 2 * Radius; Vector3D[] vertices = new Vector3D[4 + corner_v]; int vi = 0; for (int i = 0; i < 4; ++i) { vertices[vi++] = new Vector3D(signx[i] * Width / 2, 0, signy[i] * Height / 2); bool sharp = ((int)SharpCorners & (1 << i)) > 0; Arc2d arc = new Arc2d(new Vector2D(signx[i] * innerW, signy[i] * innerH), (sharp) ? math.MathUtil.SqrtTwo * Radius : Radius, startangle[i], endangle[i]); int use_steps = (sharp) ? 1 : CornerSteps; for (int k = 0; k < use_steps; ++k) { double t = (double)(i + 1) / (double)(use_steps + 1); Vector2D pos = arc.SampleT(t); vertices[vi++] = new Vector3D(pos.x, 0, pos.y); } } return(vertices); }
public void ArcToRelative2d(Vector2d v, double radius, bool clockwise, double rate = 0) { Vector2d P2 = P + v; Vector2d c0, c1; int nCenters = find_arc_centers(P, P2, radius, out c0, out c1); //bool b0Left = MathUtil.IsLeft(P, P2, c0) > 0; //bool b1Left = MathUtil.IsLeft(P, P2, c1) > 0; Vector2d c = c0; if (nCenters == 2 && clockwise == false) { c = c1; } // [RMS] what does negative radius mean ?? //bool reverse = false; //if (radius < 0) // reverse = true; radius = Math.Abs(radius); double start_angle = arc_angle_deg(P, c); double end_angle = arc_angle_deg(P2, c); if (clockwise == false) { double tmp = start_angle; start_angle = end_angle; end_angle = tmp; } Arc2d arc = new Arc2d(c, radius, start_angle, end_angle); //if (reverse) // arc.Reverse(); Complex.Add(arc); P = P2; }
private void Set_output() { if (arc1.IsSegment) { Arc1IsSegment = true; Segment1 = new Segment2d(arc1.P0, arc1.P1); } else { Arc1IsSegment = false; Arc1 = Get_arc(0); } if (arc2.IsSegment) { Arc2IsSegment = true; Segment2 = new Segment2d(arc2.P1, arc2.P0); } else { Arc2IsSegment = false; Arc2 = Get_arc(1); } }
public EntityArc(double x1, double y1, double x2, double y2, double bulge) { geometry = new Arc2d(new Point2d(x1, y1), new Point2d(x2, y2), bulge); }