public void addNeighbour(Node newNeighbour) { nS newN=new nS(); newN.neighbor = newNeighbour; newN.timer = 1; neighboursNodes.Add(newN); PrimitiveLine tempLine = new PrimitiveLine(gd); /* if (getPosition().X == newNeighbour.getPosition().X) { tempLine.AddVector(getPosition() + new Vector2(5, 0)); tempLine.AddVector(newNeighbour.getPosition()); tempLine.AddVector(getPosition() + new Vector2(-5, 0)); tempLine.AddVector(newNeighbour.getPosition()); } else { tempLine.AddVector(getPosition()+new Vector2(0,5)); tempLine.AddVector(newNeighbour.getPosition()); tempLine.AddVector(getPosition() + new Vector2(0, -5)); tempLine.AddVector(newNeighbour.getPosition()); }*/ //Simple line tempLine.AddVector(getPosition()); tempLine.AddVector(newNeighbour.getPosition()); neighbours.Add(tempLine); }
private static PolyShape Create(PrimitiveLine line) { var type = PolyShapeType.Line.ToString(); var coordinates = new List <Coordinate>(line.Points.Select(n => new Coordinate(n.Point))); return(new PolyShape(coordinates, type)); }
public Entity(Texture2D image, Vector2 position, float maxAcc, float maxSpe) { boundingCircle = new Circle(position.X, position.Y, 50); debugCircle = new PrimitiveLine(position, Color.White); debugCircle.CreateCircle(50, 20); velocity = new Vector2(); this.image = image; this.position = position; this.maxAcceleration = maxAcc; this.maxSpeed = maxSpe; rotation = orientation = wanderOrientation = 0; offsetToCenter = new Vector2(image.Width / 2, image.Height / 2); position += offsetToCenter; //for now, make max angular rotation and rotation statndard this.maxRotation = 0.2f; this.maxAngularAcceleration = 1; maxSpeedSq = maxSpeed * maxSpeed; neighbors = new List <Entity>(); wanderSpeed = 0.5f; }
internal static MapShape Create(MapWay outer, IEnumerable <MapWay> inners, IEnumerable <KeyValuePair <string, string> > tags) { var len = outer.Nodes.Count(); var outerEdge = new PrimitiveLine(outer.Nodes.Take(len - 1).Select(n => new PrimitivePoint(n.Coordinate)).ToList()); var innerEdges = inners.Select(inner => new PrimitivePolygon(new PrimitiveLine(inner.Nodes.Take(len - 1).Select(n => new PrimitivePoint(n.Coordinate)).ToList()))); var primitive = new PrimitivePolygon(outerEdge, innerEdges); return(new MapShape(primitive, tags)); }
public void LineStripsFromSinglePrimitiveTest() { var line = new PrimitiveLine(new Point(0.0, 0.0, 0.0), new Point(1.0, 0.0, 0.0)); var polylines = new[] { line }.GetPolylinesFromSegments(); var poly = polylines.Single(); var primitive = (PrimitiveLine)poly.GetPrimitives().Single(); Assert.Equal(line.P1, primitive.P1); Assert.Equal(line.P2, primitive.P2); }
public Emitter(Vector2 location, GraphicsDevice gd, ContentManager content) : base(location) { this.initialise(content); next = null; laser = new PrimitiveLine(gd); laser.Colour = Color.Red; laser.Depth = 0; laser.Position = position; on = true; }
public void OnLoadContentEvent(GameScreenManager.LoadContentEventArgs eventArgs) { List <string> enemies = new List <string> { "alien1", "alien2", "alien3" }; int index = row % enemies.Count; sprite = eventArgs.contentManager.Load <Texture2D>(enemies[index]); circle = eventArgs.contentManager.Load <Texture2D>("circle"); line = new PrimitiveLine(); line.CreateCircle(200, 40); }
public Line(PrimitiveLine line, object tag = null) : base(line.Color, tag) { _primitive = line; _primitives = new[] { _primitive }; _snapPoints = new SnapPoint[] { new EndPoint(P1), new EndPoint(P2), new MidPoint((P1 + P2) / 2.0) }; BoundingBox = BoundingBox.FromPoints(P1, P2); }
private static bool IsPointOnPrimitive(this PrimitiveLine line, Point point, bool withinSegment = true) { if (point == line.P1) { return(true); } var lineVector = line.P2 - line.P1; var pointVector = point - line.P1; return((lineVector.Normalize().CloseTo(pointVector.Normalize())) && (!withinSegment || MathHelper.Between(0.0, lineVector.LengthSquared, pointVector.LengthSquared))); }
private Shapes.Line CreatePrimitiveLine(PrimitiveLine line, CadColor?color) { var p1 = PlaneProjection.Transform(line.P1); var p2 = PlaneProjection.Transform(line.P2); var newLine = new Shapes.Line() { X1 = p1.X, Y1 = p1.Y, X2 = p2.X, Y2 = p2.Y }; SetThicknessBinding(newLine); SetColor(newLine, color); return(newLine); }
private void SetupCircles() { int maxLines = 16000; fLines = new PrimitiveLine(fSpriteBatch.GraphicsDevice); bool first = true; while (fLines.Lines < maxLines) { //int w = Game.GraphicsDevice.Viewport.Width; //int h = Game.GraphicsDevice.Viewport.Height; float x = (float)(1500.0f * (fRandom.NextDouble() - 0.5f)); float y = (float)(1500.0f * (fRandom.NextDouble() - 0.5f)); int radius = fRandom.Next(400) + 10; int segments = 50; byte r = (byte)fRandom.Next(256); byte g = (byte)fRandom.Next(256); byte b = (byte)fRandom.Next(256); byte a = 255; if (first) { x = 0; y = 0; radius = 500; r = 255; g = 255; b = 255; first = false; } while (fLines.Lines < maxLines && radius > 20) { Color color = new Color(r, g, b, a); fLines.AddCircle(x, y, 0, radius, segments, color); radius -= 20; x++; if (r > 10) { r -= 10; } if (g > 10) { g -= 10; } if (b > 10) { b -= 10; } } } }
/// <summary> /// Loads any component specific content /// </summary> protected override void LoadContent() { fSpriteBatch = new SpriteBatch(Game.GraphicsDevice); InitializeTransform(); InitializeEffect(); fModel1 = this.Game.Content.Load <Model>("MyFirstModel/grid"); fModel2 = this.Game.Content.Load <Model>("MyFirstModel/dude"); fLines = new PrimitiveLine(Game.GraphicsDevice); fLines.AddLine( new VertexPositionColor(new Vector3(0, 0, 0), Color.Red), new VertexPositionColor(new Vector3(1000, 0, 0), Color.Yellow)); fLines.AddLine( new VertexPositionColor(new Vector3(0, 0, 0), Color.Green), new VertexPositionColor(new Vector3(0, 1000, 0), Color.LightGreen)); fLines.AddLine( new VertexPositionColor(new Vector3(0, 0, 0), Color.Blue), new VertexPositionColor(new Vector3(0, 0, 1000), Color.Cyan)); fLines.AddLine( new VertexPositionColor(new Vector3(0, 0, 0), Color.DarkRed), new VertexPositionColor(new Vector3(-1000, 0, 0), Color.DarkRed)); fLines.AddLine( new VertexPositionColor(new Vector3(0, 0, 0), Color.DarkGreen), new VertexPositionColor(new Vector3(0, -1000, 0), Color.DarkGreen)); fLines.AddLine( new VertexPositionColor(new Vector3(0, 0, 0), Color.DarkBlue), new VertexPositionColor(new Vector3(0, 0, -1000), Color.DarkBlue)); for (int r = 0; r < 360; r += 10) { float angle = MathHelper.ToRadians(r); fLines.AddCircle(0, 35, 0, 40, 50, Color.Red, 0, 0); fLines.AddCircle(0, 35, 0, 40, 50, Color.Tomato, angle, 0); fLines.AddCircle(0, 35, 0, 40, 50, Color.Orange, 0, angle); } fStateBlend = BlendState.Opaque; fStateDepth = DepthStencilState.Default; fStateNoDepth = DepthStencilState.None; fStateRasterizer = new RasterizerState() { FillMode = FillMode.Solid, CullMode = CullMode.None }; fStateSampler = new SamplerState() { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap }; base.LoadContent(); }
public static IEnumerable <PrimitiveLine> GetLinesFromPoints(this IEnumerable <Point> points) { var lines = new List <PrimitiveLine>(); var last = points.First(); foreach (var point in points.Skip(1)) { var line = new PrimitiveLine(last, point); lines.Add(line); last = point; } return(lines); }
public async Task <bool> Execute(IWorkspace workspace, object arg) { var drawingPlane = workspace.DrawingPlane; var center = await workspace.InputService.GetPoint(new UserDirective("Center")); if (!center.Cancel && center.HasValue) { var majorEnd = await workspace.InputService.GetPoint(new UserDirective("Major axis endpoint"), p => { return(new[] { new PrimitiveLine(center.Value, p) }); }); var majorPrimitive = new PrimitiveLine(center.Value, majorEnd.Value); var majorAxis = majorEnd.Value - center.Value; var majorAxisLength = majorAxis.Length; if (!majorEnd.Cancel && majorEnd.HasValue) { var minorEnd = await workspace.InputService.GetPoint(new UserDirective("Minor axis endpoint"), lastPoint : center.Value, onCursorMove : p => { var tempMinorAxis = p - center.Value; var tempMinorAxisRatio = tempMinorAxis.Length / majorAxisLength; var el = new PrimitiveEllipse(center.Value, majorAxis, drawingPlane.Normal, tempMinorAxisRatio, 0.0, 360.0); return(new IPrimitive[] { majorPrimitive, // major axis line new PrimitiveLine(center.Value, p), // minor axis line el // the ellipse }); }); if (!minorEnd.Cancel && minorEnd.HasValue) { var minorAxis = minorEnd.Value - center.Value; var minorAxisRatio = minorAxis.Length / majorAxisLength; if (!minorEnd.Cancel && minorEnd.HasValue) { var el = new Ellipse(center.Value, majorAxis, minorAxisRatio, 0.0, 360.0, drawingPlane.Normal); workspace.AddToCurrentLayer(el); return(true); } } } } return(false); }
void Awake() { gameObject.layer = 2; line = new GameObject("debug line").AddComponent <PrimitiveLine>(); line.transform.SetParent(transform); lineRenderer = gameObject.AddComponent <LineRenderer>(); lineRenderer.startWidth = 2; lineRenderer.endWidth = 2; lineRenderer.SetPosition(0, Vector3.zero); lineRenderer.SetPosition(1, Vector3.zero); lineRenderer.sharedMaterial = new Material(Shader.Find("Unlit/Transparent")); }
internal static MapShape Create(MapWay way, IEnumerable <KeyValuePair <string, string> > tags) { if (way.IsClosed) { var len = way.Nodes.Count(); var outerEdge = new PrimitiveLine(way.Nodes.Take(len - 1).Select(n => new PrimitivePoint(n.Coordinate)).ToList()); var primitive = new PrimitivePolygon(outerEdge, Enumerable.Empty <PrimitivePolygon>()); return(new MapShape(primitive, tags)); } else { var primitive = new PrimitiveLine(way.Nodes.Select(n => new PrimitivePoint(n.Coordinate)).ToList()); return(new MapShape(primitive, tags)); } }
public void RectDoesNotContainPartial() { // / <- line // / // +--------+ / // + + / // + + / // + + // +--------+ <- selection rectangle var rect = new Rect(left: 0.0, top: 0.0, width: 1.0, height: 1.0); var line = new PrimitiveLine(new Point(1.5, 0.5, 0.0), new Point(3.0, 2.0, 0.0)); var points = new[] { line.P1, line.P2 }; var isContained = rect.Contains(points, includePartial: true); Assert.False(isContained); }
public override void LoadContent(ContentManager contentManager) { var device = Services.GetService <GraphicsDevice>(); var behaviorTreeService = Services.GetService <AIService>(); AIExecutionContext = new AIExecutionContext() { LivingGameObject = this, Services = Services }; BehaviorTree = behaviorTreeService.GetBehaviorTreeThatAppliesTo(this.GetType().Name); behaviorTreeService.Register(this); _line = new PrimitiveLine(device, Color.Red); }
public static bool PolygonContains(this IEnumerable <IPrimitive> primitives, Point point) { // TODO: this kind of ray casing can fail if the ray and a primitive line are part of the // same infinite line or if the ray barely skims the other primitive var maxX = primitives.Select(p => Math.Max(p.StartPoint().X, p.EndPoint().X)).Max(); var dist = Math.Abs(maxX - point.X); var ray = new PrimitiveLine(point, new Point(point.X + (dist * 1.1), point.Y, point.Z)); int intersections = 0; foreach (var primitive in primitives) { intersections += ray.IntersectionPoints(primitive).Count(); } return(intersections % 2 == 1); }
public static IEnumerable <Point> IntersectionPoints(this PrimitiveLine line, IPrimitive other, bool withinBounds = true) { IEnumerable <Point> result; switch (other.Kind) { case PrimitiveKind.Line: var p = line.IntersectionPoint((PrimitiveLine)other, withinBounds); if (p.HasValue) { result = new[] { p.Value } } ; else { result = new Point[0]; } break; case PrimitiveKind.Ellipse: result = line.IntersectionPoints((PrimitiveEllipse)other, withinBounds); break; case PrimitiveKind.Point: var point = (PrimitivePoint)other; if (line.IsPointOnPrimitive(point.Location, withinBounds)) { result = new Point[] { point.Location }; } else { result = new Point[0]; } break; case PrimitiveKind.Text: result = Enumerable.Empty <Point>(); break; default: Debug.Assert(false, "Unsupported primitive type"); result = Enumerable.Empty <Point>(); break; } return(result); }
public static double PerpendicularSlope(this PrimitiveLine line) { var slope = line.Slope(); if (double.IsNaN(slope)) { return(0.0); } else if (slope == 0.0) { return(double.NaN); } else { return(-1.0 / slope); } }
private void SetupTree() { int maxLines = 16000; fLines = new PrimitiveLine(fSpriteBatch.GraphicsDevice); double maxRadius = Game.GraphicsDevice.Viewport.Width / 4.0f; while (fLines.Lines < maxLines) { byte r = (byte)fRandom.Next(256); byte g = (byte)fRandom.Next(256); byte b = (byte)fRandom.Next(256); byte a = 0; Color c = new Color(r, g, b, a); VertexPositionColor p1 = new VertexPositionColor(new Vector3(0, 0, 0), c); AddTreeBranch(p1, 8, maxRadius, maxLines); } }
public static IEnumerable <IEnumerable <IPrimitive> > GetLineStripsFromPrimitives(this IEnumerable <IPrimitive> primitives) { var remainingPrimitives = new HashSet <IPrimitive>(primitives); var result = new List <List <IPrimitive> >(); while (remainingPrimitives.Count > 1) { var shapePrimitives = new List <IPrimitive>(); var first = remainingPrimitives.First(); remainingPrimitives.Remove(first); shapePrimitives.Add(first); while (remainingPrimitives.Count > 0) { var nextPrimitive = remainingPrimitives.FirstOrDefault(l => l.StartPoint().CloseTo(shapePrimitives.Last().EndPoint()) || l.EndPoint().CloseTo(shapePrimitives.Last().EndPoint())); if (nextPrimitive == null) { // no more segments break; } remainingPrimitives.Remove(nextPrimitive); if (!nextPrimitive.StartPoint().CloseTo(shapePrimitives.Last().EndPoint()) && nextPrimitive.Kind == PrimitiveKind.Line) { // need to flip the line; arcs are handled elsewhere var line = (PrimitiveLine)nextPrimitive; nextPrimitive = new PrimitiveLine(line.P2, line.P1, line.Color); } shapePrimitives.Add(nextPrimitive); } result.Add(shapePrimitives); } return(result); }
public static Point ClosestPoint(this PrimitiveLine line, Point point, bool withinBounds = true) { var v = line.P1; var w = line.P2; var p = point; var wv = w - v; var l2 = wv.LengthSquared; if (Math.Abs(l2) < MathHelper.Epsilon) { return(v); } var t = (p - v).Dot(wv) / l2; if (withinBounds) { t = Math.Max(t, 0.0 - MathHelper.Epsilon); t = Math.Min(t, 1.0 + MathHelper.Epsilon); } var result = v + (wv) * t; return(result); }
public LineEditViewModel(PrimitiveLine line) { this.baseLine = line; this.currentLine = (PrimitiveLine)line.Clone(); }
public static bool IsPoint(this PrimitiveLine line) { return(line.LengthSquared <= MathHelper.Epsilon); }
public static IPrimitive Offset(Plane drawingPlane, IPrimitive primitive, Point offsetDirection, double offsetDistance) { if (!drawingPlane.Contains(offsetDirection)) { return(null); } IPrimitive result; switch (primitive.Kind) { case PrimitiveKind.Ellipse: var el = (PrimitiveEllipse)primitive; var projection = el.FromUnitCircle.Inverse(); var isInside = projection.Transform((Vector)offsetDirection).LengthSquared <= 1.0; var majorLength = el.MajorAxis.Length; if (isInside && (offsetDistance > majorLength * el.MinorAxisRatio) || (offsetDistance >= majorLength)) { result = null; } else { Vector newMajor; if (isInside) { newMajor = el.MajorAxis.Normalize() * (majorLength - offsetDistance); } else { newMajor = el.MajorAxis.Normalize() * (majorLength + offsetDistance); } result = new PrimitiveEllipse( center: el.Center, majorAxis: newMajor, normal: el.Normal, minorAxisRatio: el.MinorAxisRatio, startAngle: el.StartAngle, endAngle: el.EndAngle, color: el.Color); } break; case PrimitiveKind.Line: // find what side the offset occured on and move both end points var line = (PrimitiveLine)primitive; // normalize to XY plane var picked = drawingPlane.ToXYPlane(offsetDirection); var p1 = drawingPlane.ToXYPlane(line.P1); var p2 = drawingPlane.ToXYPlane(line.P2); var pline = new PrimitiveLine(p1, p2); var perpendicular = new PrimitiveLine(picked, pline.PerpendicularSlope()); var intersection = pline.IntersectionPoint(perpendicular, false); if (intersection.HasValue && intersection.Value != picked) { var offsetVector = (picked - intersection.Value).Normalize() * offsetDistance; offsetVector = drawingPlane.FromXYPlane(offsetVector); result = new PrimitiveLine( p1: line.P1 + offsetVector, p2: line.P2 + offsetVector, color: line.Color); } else { // the selected point was directly on the line result = null; } break; case PrimitiveKind.Point: var point = (PrimitivePoint)primitive; var pointOffsetVector = (offsetDirection - point.Location).Normalize() * offsetDistance; result = new PrimitivePoint(point.Location + pointOffsetVector, point.Color); break; case PrimitiveKind.Text: result = null; break; default: throw new ArgumentException("primitive.Kind"); } return(result); }
public static Point?IntersectionPoint(this PrimitiveLine first, PrimitiveLine second, bool withinSegment = true) { // TODO: need to handle a line's endpoint lying directly on the other line // TODO: also need to handle colinear lines var minLength = 0.0000000001; //http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline3d/ // find real 3D intersection within a minimum distance var p1 = first.P1; var p2 = first.P2; var p3 = second.P1; var p4 = second.P2; var p13 = p1 - p3; var p43 = p4 - p3; if (p43.LengthSquared < MathHelper.Epsilon) { return(null); } var p21 = p2 - p1; if (p21.LengthSquared < MathHelper.Epsilon) { return(null); } var d1343 = p13.Dot(p43); var d4321 = p43.Dot(p21); var d1321 = p13.Dot(p21); var d4343 = p43.Dot(p43); var d2121 = p21.Dot(p21); var denom = d2121 * d4343 - d4321 * d4321; if (Math.Abs(denom) < MathHelper.Epsilon) { return(null); } var num = d1343 * d4321 - d1321 * d4343; var mua = num / denom; var mub = (d1343 + d4321 * mua) / d4343; if (withinSegment) { if (!MathHelper.Between(0.0, 1.0, mua) || !MathHelper.Between(0.0, 1.0, mub)) { return(null); } } var connector = new PrimitiveLine((p21 * mua) + p1, (p43 * mub) + p3); var cv = connector.P1 - connector.P2; if (cv.LengthSquared > minLength) { return(null); } var point = (Point)((connector.P1 + connector.P2) / 2); return(point); }
public void updateNeighbours() { clearNeighboursLines(); foreach (nS n in neighboursNodes) { PrimitiveLine tempLine = new PrimitiveLine(gd); /* if (getPosition().X == n.neighbor.getPosition().X) { tempLine.AddVector(getPosition() + new Vector2(5, 0)); tempLine.AddVector(n.neighbor.getPosition()); tempLine.AddVector(getPosition() + new Vector2(-5, 0)); tempLine.AddVector(n.neighbor.getPosition()); } else { tempLine.AddVector(getPosition() + new Vector2(0, 5)); tempLine.AddVector(n.neighbor.getPosition()); tempLine.AddVector(getPosition() + new Vector2(0, -5)); tempLine.AddVector(n.neighbor.getPosition()); }*/ //Simple line tempLine.AddVector(getPosition()); tempLine.AddVector(n.neighbor.getPosition()); neighbours.Add(tempLine); } }
public static double Slope(this PrimitiveLine line) { var denom = line.P2.X - line.P1.X; return(denom == 0.0 ? double.NaN : (line.P2.Y - line.P1.Y) / denom); }
private void initBorderLines() { PrimitiveLine tempLine = new PrimitiveLine(GraphicsDevice); tempLine.AddVector(Vector2.Zero); tempLine.AddVector(new Vector2(screenWidth ,0)); tempLine.AddVector(new Vector2(screenWidth, 0)); tempLine.AddVector(new Vector2(screenWidth, screenHeight )); tempLine.AddVector(new Vector2(screenWidth, screenHeight )); tempLine.AddVector(new Vector2(0, screenHeight)); tempLine.AddVector(new Vector2(0, screenHeight)); tempLine.AddVector(Vector2.Zero); borderLines.Add(tempLine); }
private void initGrid(int gridSize) { for (int i = 1; i < gridSize; i++) { PrimitiveLine tempLine = new PrimitiveLine(GraphicsDevice); tempLine.AddVector(new Vector2(0,i*screenHeight / gridSize)); tempLine.AddVector(new Vector2(screenWidth, i * screenHeight / gridSize)); gridLines.Add(tempLine); tempLine = new PrimitiveLine(GraphicsDevice); tempLine.AddVector(new Vector2(i * screenWidth / gridSize, 0)); tempLine.AddVector(new Vector2(i * screenWidth / gridSize, screenHeight)); gridLines.Add(tempLine); } }
private void OnLoadContentEvent(GameScreenManager.LoadContentEventArgs eventArgs) { circle = eventArgs.contentManager.Load <Texture2D>("circle"); line = new PrimitiveLine(); line.CreateCircle(200, 1000); }
/// <summary> /// Using algorithm as described at http://www.ceometric.com/support/examples/v-ellipse-projection-using-rytz-construction.html /// </summary> public static ProjectedCircle FromConjugateDiameters(Circle originalCircle, Layer originalLayer, Point center, Point majorAxisConjugate, Point minorAxisConjugate) { // re-map to shorter variables var m = center; var p = majorAxisConjugate; var q = minorAxisConjugate; // PM must be longer than QM. Swap if necessary. var pm = p - m; var qm = q - m; if (pm.LengthSquared > qm.LengthSquared) { var temp = p; p = q; q = temp; pm = p - m; qm = q - m; } // if axes are already orthoganal, no transform is needed if (MathHelper.CloseTo(0.0, pm.Dot(qm))) { return(new ProjectedCircle(originalCircle, originalLayer, m, qm.Length, pm.Length, 0.0)); } // find the plane containing the projected ellipse var plane = Plane.From3Points(m, p, q); // rotate P by 90 degrees around the normal var rotationMatrix = Matrix4.Identity; rotationMatrix.RotateAt(new Quaternion(plane.Normal, 90.0), m); var rotp = rotationMatrix.Transform(p); // the angle between (rotp-M) and (Q-M) should be less than 90 degrees. mirror if not if (Vector.AngleBetween(rotp - m, qm) > 90.0) { rotp = ((rotp - m) * -1.0) + m; } // construct the rytz circle // the center is the midpoint of the edge from rotp to Q // the radius is the distance from M to the center // the normal is the normal of the plane var rc = (rotp + q) / 2.0; var rytz = new PrimitiveEllipse(rc, (m - rc).Length, plane.Normal); // intersect the rytz circle with a line passing through the center and Q var intersectingLine = new PrimitiveLine(rc, q); var intersectingPoints = intersectingLine.IntersectionPoints(rytz, false).ToList(); if (intersectingPoints.Count != 2) { return(null); } var da = (q - intersectingPoints[0]).Length; var db = (q - intersectingPoints[1]).Length; if (da < db) { // da must be large than db var temp = da; da = db; db = temp; } // get main axes var a = intersectingPoints[0] - m; var b = intersectingPoints[1] - m; if (b.LengthSquared > a.LengthSquared) { var temp = a; a = b; b = temp; } // return the new ellipse return(new ProjectedCircle(originalCircle, originalLayer, m, da, db, a.ToAngle() * -1.0)); }
public static IPrimitive Offset(Plane drawingPlane, IPrimitive primitive, Point offsetDirection, double offsetDistance) { if (!drawingPlane.Contains(offsetDirection)) { return(null); } return(primitive.MapPrimitive <IPrimitive>( ellipse => { var projection = ellipse.FromUnitCircle.Inverse(); var isInside = projection.Transform((Vector)offsetDirection).LengthSquared <= 1.0; var majorLength = ellipse.MajorAxis.Length; if (isInside && (offsetDistance > majorLength * ellipse.MinorAxisRatio) || (offsetDistance >= majorLength)) { return null; } else { Vector newMajor; if (isInside) { newMajor = ellipse.MajorAxis.Normalize() * (majorLength - offsetDistance); } else { newMajor = ellipse.MajorAxis.Normalize() * (majorLength + offsetDistance); } return new PrimitiveEllipse( center: ellipse.Center, majorAxis: newMajor, normal: ellipse.Normal, minorAxisRatio: ellipse.MinorAxisRatio, startAngle: ellipse.StartAngle, endAngle: ellipse.EndAngle, color: ellipse.Color); } }, line => { // find what side the offset occured on and move both end points // normalize to XY plane var picked = drawingPlane.ToXYPlane(offsetDirection); var p1 = drawingPlane.ToXYPlane(line.P1); var p2 = drawingPlane.ToXYPlane(line.P2); var pline = new PrimitiveLine(p1, p2); var perpendicular = new PrimitiveLine(picked, pline.PerpendicularSlope()); var intersection = pline.IntersectionPoint(perpendicular, false); if (intersection.HasValue && intersection.Value != picked) { var offsetVector = (picked - intersection.Value).Normalize() * offsetDistance; offsetVector = drawingPlane.FromXYPlane(offsetVector); return new PrimitiveLine( p1: line.P1 + offsetVector, p2: line.P2 + offsetVector, color: line.Color); } else { // the selected point was directly on the line return null; } }, point => { var pointOffsetVector = (offsetDirection - point.Location).Normalize() * offsetDistance; return new PrimitivePoint(point.Location + pointOffsetVector, point.Color); }, text => null, bezier => null, image => null )); }