예제 #1
0
        private static IEnumerable <IEntity2D> CreateRadius(Arc2D arc, Line2D line, double radiusValue, out bool radiusSuccess)
        {
            Arc2D filletArc = null;

            var rsl = GeometryHelper.FilletEntity(arc, line, radiusValue, false, out filletArc);

            if (rsl)
            {
                var lineWithRadius = new List <IEntity2D>();

                /*
                 *
                 *
                 */
                arc.End    = filletArc.Start;
                line.Start = filletArc.End;

                lineWithRadius.Add(arc);
                lineWithRadius.Add(filletArc);

                foreach (var entity2D in lineWithRadius)
                {
                    entity2D.PlotStyle = arc.PlotStyle;
                }


                radiusSuccess = true;
                return(lineWithRadius);
            }

            radiusSuccess = false;
            return(null);
        }
예제 #2
0
        private static IEnumerable <IEntity2D> CreateRadius(Arc2D arc1, Arc2D arc2, double radiusValue, out bool radiusSuccess)
        {
            radiusSuccess = false;
            return(null);
            //var arc = new Arc2D()
            //{
            //    Start = new Point2D(19.5002, 6.878),
            //    End = new Point2D(0, 10),
            //    Center = new Point2D(10, 10),
            //    Radius = 10,

            //};

            //var line = new Line2D()
            //{
            //    Start = new Point2D(40.43, 0),
            //    End = new Point2D(19.5, 6.878),
            //};

            //var offsetArc = GeometryHelper.GetParallel(arc, 4, profileLeft);
            //var offsetLine = GeometryHelper.GetParallel(line, 4, profileLeft);

            //var pIncontro = GeometryHelper.GetIntersectPoint(offsetArc, offsetLine);

            //var raccordo = new Arc2D();
            //raccordo.Center = pIncontro;
            //raccordo.Radius = 4;

            //var pAttaccoLinea = GeometryHelper.GetIntersectPoint(raccordo, line);
            //var pAttaccoRaggio = GeometryHelper.GetIntersectPoint(raccordo, arc, pIncontro);
        }
예제 #3
0
        public Profile2D GetClosedProfile()
        {
            var interasseArc = new Arc2D()
            {
                Center = new Point2D(CentroX, CentroY)
            };

            var clockWise = false;

            var angoloStartRad = GeometryHelper.DegreeToRadian(AngoloStart);
            var angoloEndRad   = GeometryHelper.DegreeToRadian(AngoloStart + AngoloAmpiezza);

            interasseArc.Radius    = RaggioInterasse;
            interasseArc.ClockWise = false;

            interasseArc.Start = GeometryHelper.GetCoordinate(angoloStartRad, RaggioInterasse);
            interasseArc.End   = GeometryHelper.GetCoordinate(angoloEndRad, RaggioInterasse);

            var offset = Larghezza / 2;
            var arc1   = GeometryHelper.GetParallel(interasseArc, offset, true);

            arc1.ClockWise = false;
            var arc2 = GeometryHelper.GetParallel(interasseArc, offset, false);

            arc2.ClockWise = true;

            var temp = arc2.Start;

            arc2.Start = arc2.End;
            arc2.End   = temp;

            var arcEndCaps = new Arc2D()
            {
                Center    = interasseArc.End,
                ClockWise = true,
                Start     = arc1.End,
                End       = arc2.Start,
                Radius    = Larghezza / 2,
            };

            var arcStartCaps = new Arc2D()
            {
                Center    = interasseArc.Start,
                ClockWise = true,
                Start     = arc2.End,
                End       = arc1.Start,
                Radius    = Larghezza / 2,
            };

            var profile2D = new Profile2D();

            profile2D.AddEntity(arc1);
            profile2D.AddEntity(arcEndCaps);
            profile2D.AddEntity(arc2);
            profile2D.AddEntity(arcStartCaps);

            arc1.PlotStyle = arc2.PlotStyle = arcStartCaps.PlotStyle = arcEndCaps.PlotStyle = EnumPlotStyle.Element;
            return(profile2D);
        }
예제 #4
0
        private static IEnumerable <IEntity2D> CreateChamfer(Line2D line, Arc2D arc2D, double radiusValue, out bool radiusSuccess)
        {
            var rsl = ChamferEntity(arc2D, line, radiusValue, true, out radiusSuccess);

            if (radiusSuccess)
            {
                return(rsl);
            }

            return(null);
        }
예제 #5
0
        private void UpdateGeometry()
        {
            /*
             * se centro xy non è definito..
             */
            _geometry = null;

            /*
             * qui mi devo basare sui punti che ho
             * non devo fare calcoli ulteriori , se defined procedo , altrimenti mi attcco
             */


            if (IsDefined && _prevTeoricalPnt != null && _endPnt != null)
            {
                if (!X.Value.HasValue || !Y.Value.HasValue || !Radius.Value.HasValue)
                {
                    return;
                }

                var arc = new Arc2D
                {
                    End = new Point2D(X.Value.Value, Y.Value.Value),

                    Radius = Radius.Value.Value,

                    Start = new Point2D(_prevTeoricalPnt),

                    ClockWise = IsClockwise,
                };

                if (CenterX.Value.HasValue)
                {
                    arc.Center.X = CenterX.Value.Value;
                }

                if (CenterY.Value.HasValue)
                {
                    arc.Center.Y = CenterY.Value.Value;
                }

                arc.PlotStyle = IsSelected ? EnumPlotStyle.SelectedElement : EnumPlotStyle.Element;

                _geometry = arc;

                // Set Plot Style
                if (PlotStyle == EnumPlotStyle.Invisible)
                {
                    _geometry.PlotStyle = EnumPlotStyle.Invisible;
                }
            }
        }
예제 #6
0
        internal ArcIterator(Arc2D a, AffineTransform at)
        {
            this.w        = a.Width / 2;
            this.h        = a.Height / 2;
            this.x        = a.X + w;
            this.y        = a.Y + h;
            this.AngStRad = -Math.ToRadians(a.GetAngleStart());
            this.Affine   = at;
            double ext = -a.AngleExtent;

            if (ext >= 360.0 || ext <= -360)
            {
                ArcSegs        = 4;
                this.Increment = Math.PI / 2;
                // btan(Math.PI / 2);
                this.Cv = 0.5522847498307933;
                if (ext < 0)
                {
                    Increment = -Increment;
                    Cv        = -Cv;
                }
            }
            else
            {
                ArcSegs        = (int)System.Math.Ceiling(System.Math.Abs(ext) / 90.0);
                this.Increment = Math.ToRadians(ext / ArcSegs);
                this.Cv        = Btan(Increment);
                if (Cv == 0)
                {
                    ArcSegs = 0;
                }
            }
            switch (a.ArcType)
            {
            case Arc2D.OPEN:
                LineSegs = 0;
                break;

            case Arc2D.CHORD:
                LineSegs = 1;
                break;

            case Arc2D.PIE:
                LineSegs = 2;
                break;
            }
            if (w < 0 || h < 0)
            {
                ArcSegs = LineSegs = -1;
            }
        }
예제 #7
0
        public static double[] GetIntersectionAngles(Segment2D line, Arc2D arc)
        {
            Vector2D delta    = line.GetDelta();
            double   num1     = delta.X * delta.X + delta.Y * delta.Y;
            Vector2D vector2D = line.Start - arc.Center;
            double   num2     = 2.0 * (vector2D.X * delta.X + vector2D.Y * delta.Y);
            double   num3     = vector2D.X * vector2D.X + vector2D.Y * vector2D.Y - arc.Radius * arc.Radius;
            double   d        = num2 * num2 - 4.0 * num1 * num3;

            if (d < 0.0)
            {
                return(new double[0]);
            }
            double         num4           = System.Math.Sqrt(d);
            double         num5           = (-num2 - num4) / (2.0 * num1);
            List <double>  doubleList     = new List <double>(2);
            AngleIntervalD angleIntervalD = new AngleIntervalD(arc.StartAngle, arc.EndAngle);

            if (num5 >= 0.0 && num5 <= 1.0)
            {
                double x    = vector2D.X + delta.X * num5;
                double num6 = System.Math.Atan2(vector2D.Y + delta.Y * num5, x);
                if (num6 < 0.0)
                {
                    num6 += 2.0 * System.Math.PI;
                }
                if (angleIntervalD.Contains(num6))
                {
                    doubleList.Add(num6);
                }
            }
            if (num4 != 0.0)
            {
                double num6 = (-num2 + num4) / (2.0 * num1);
                if (num6 >= 0.0 && num6 <= 1.0)
                {
                    double x    = vector2D.X + delta.X * num6;
                    double num7 = System.Math.Atan2(vector2D.Y + delta.Y * num6, x);
                    if (num7 < 0.0)
                    {
                        num7 += 2.0 * System.Math.PI;
                    }
                    if (angleIntervalD.Contains(num7))
                    {
                        doubleList.Add(num7);
                    }
                }
            }
            return(doubleList.ToArray());
        }
예제 #8
0
 public override ICurve2D GetProjectedCurve(ICurve curve, double precision)
 {
     if (curve is Line line)
     {
         // this must be a line through the apex, otherwise there are no lines on the cone
         // if it is an extremely small line not through the apex, the result will also be a line, which
         // in reverse projection will give a very short ellipse
         return(new Line2D(PositionOf(line.StartPoint), PositionOf(line.EndPoint)));
     }
     else if (curve is Ellipse elli)
     {
         if (elli.IsCircle)
         {
             GeoPoint2D sp2d = PositionOf(elli.StartPoint);
             if (elli.IsArc)
             {
             }
             else
             {
                 Arc2D     a2d  = new Arc2D(GeoPoint2D.Origin, sp2d.ToVector().Length, sp2d, sp2d, true);
                 GeoVector sdir = a2d.StartDirection.x * UDirection(sp2d) + a2d.StartDirection.y * VDirection(sp2d);
                 if (sdir * elli.StartDirection < 0)
                 {
                     a2d.counterClock = false;
                 }
                 return(a2d);
             }
         }
         else
         {
             // this is a intersection with a plane.
             GeoPoint2D[] fp2d = new GeoPoint2D[5];
             double       n    = 5.0;
             if (elli.IsArc)
             {
                 n = 4.0;
             }
             for (int i = 0; i < 5; i++)
             {
                 fp2d[i] = PositionOf(elli.PointAt(i / n));
             }
             Ellipse2D elli2d = Ellipse2D.FromFivePoints(fp2d, !elli.IsArc); // returns both full ellipse and ellipse arc
             if (elli2d != null)
             {
                 return(elli2d);
             }
         }
     }
     return(base.GetProjectedCurve(curve, precision));
 }
예제 #9
0
        //public override void SetZeroPoint(Point3D point3D)
        //{
        //    throw new NotImplementedException();
        //}

        private void MoveArcWork(Arc2D arc, ref StringBuilder code)
        {
            var moveTypeCmd = string.Empty;

            var moveType = arc.ClockWise ? MoveType.Cw : MoveType.Ccw;

            if (CurrentMoveType != moveType)
            {
                CurrentMoveType = moveType;

                moveTypeCmd = arc.ClockWise ? NumericControl.CMD_MoveCW : NumericControl.CMD_MoveCCW;
            }

            code.AppendLine(moveTypeCmd + "X" + arc.End.Y + "Z" + arc.End.X);
        }
예제 #10
0
 private ICurve2D fromPeriodic(ICurve2D curve2d)
 {
     // gegeben: Kurve im periodischen System, gesucht: Kurve im nichtperiodischen System
     if (curve2d is Line2D)
     {
         Line2D l2d = curve2d as Line2D;
         if (Math.Abs(l2d.StartDirection.y) < 1e-6)
         {   // horizontale Linie im periodischen System wird Kreisbogen um den Mittelpunkt im nichtperiodischen System
             Arc2D a2d = new Arc2D(GeoPoint2D.Origin, l2d.StartPoint.y - vmin, fromPeriodic(l2d.StartPoint), fromPeriodic(l2d.EndPoint), l2d.EndPoint.x > l2d.StartPoint.x);
             return(a2d);
         }
         if (Math.Abs(l2d.StartDirection.x) < 1e-6)
         {   // vertikale Linie um periodischen System sollte Linie durch den Ursprung im nichtperiodischen System werden
             return(new Line2D(fromPeriodic(l2d.StartPoint), fromPeriodic(l2d.EndPoint)));
         }
     }
     return(new TransformedCurve2D(curve2d, new NonPeriodicTransformation(vmin)));
 }
예제 #11
0
        /// <summary>
        /// 判断画布中某个位置是否在某个圆弧附近;
        /// </summary>
        /// <param name="arc2D"></param>
        /// <param name="point"></param>
        /// <param name="canvasProxy"></param>
        /// <returns></returns>
        public static bool PointInArc(Arc2D arc2D, Vector2D point, ICanvasScreenConvertable canvasProxy)
        {
            if (canvasProxy == null)
            {
                return(false);
            }

            if (arc2D == null)
            {
                return(false);
            }

            //以视图单位为标准进行判断;
            var screenPoint          = canvasProxy.ToScreen(point);
            var arcCenterScreenPoint = canvasProxy.ToScreen(arc2D.Center);
            var screenRadius         = canvasProxy.ToScreen(arc2D.Radius);

            if (Math.Abs(arcCenterScreenPoint.Distance(screenPoint) - screenRadius) > TolerantedScreenLength)
            {
                return(false);
            }

            var centerToPointDirection = new Line2D(arc2D.Center, point).Direction;

            if (Extension.AreEqual(centerToPointDirection.Modulus(), 0))
            {
                return(false);
            }

            var centerToPointAngle = Extension.AngleFrom(
                new Vector3D(centerToPointDirection.X, centerToPointDirection.Y, 0),
                Vector3D.BasisX
                );

            if (arc2D.Angle > 0)
            {
                return(centerToPointAngle < arc2D.StartAngle + arc2D.Angle && centerToPointAngle > arc2D.StartAngle);
            }
            else
            {
                return(centerToPointAngle < arc2D.StartAngle && centerToPointAngle > arc2D.StartAngle + arc2D.Angle);
            }
        }
예제 #12
0
        private static Point2D GetInitChamferPointOnCfr(Arc2D cfrToChamfer, Point2D intersectPoint, double chamferValue, bool lineFirst)
        {
            // creo linea normale di lunghezza 1
            var normalAngle = GeometryHelper.getNormalAngle(cfrToChamfer, intersectPoint);

            var normalEndpoint = GeometryHelper.GetCoordinate(normalAngle, 1);

            normalEndpoint.X += intersectPoint.X;
            normalEndpoint.Y += intersectPoint.Y;

            // trovo intersezioni tra cerchio da smussare  e cerchio costruito sul punto di intersect
            Point2D p1 = null;
            Point2D p2 = null;

            var pFlag = GeometryHelper.FindCircleCircleIntersections(cfrToChamfer.Center.X, cfrToChamfer.Center.Y, cfrToChamfer.Radius, intersectPoint.X, intersectPoint.Y, chamferValue, out p1, out p2);

            if (pFlag == 2) // in questo metodo dovrebbe sempre restituire 2 punti ..
            {
                var d1 = GeometryHelper.Distance(normalEndpoint, p1);
                var d2 = GeometryHelper.Distance(normalEndpoint, p2);

                if (lineFirst)
                {
                    if (d1 < d2)
                    {
                        return(p1);
                    }
                    return(p2);
                }
                else
                {
                    if (d1 > d2)
                    {
                        return(p1);
                    }
                    return(p2);
                }
            }
            else
            {
                throw new Exception("RawProfile.GetInitChamferPointOnCfr");
            }
        }
예제 #13
0
    public static bool DoArc2DHandleInteraction(Arc2D arc, ref Vector2 centre, int hash, bool wasSelectedLast, Color lineColor, Color arcColor)
    {
        Event e = Event.current;

        DrawArc2DHandle(arc, centre, hash, lineColor, arcColor, e);
        if (wasSelectedLast || (HandleUtility.nearestControl == hash && e.type == e.GetTypeForControl(hash) && e.type == EventType.MouseDown))
        {
            Ray   r      = HandleUtility.GUIPointToWorldRay(e.mousePosition);
            Plane p      = new Plane(Vector3.forward, 0);
            float outHit = 0;
            if (p.Raycast(r, out outHit))
            {
                Vector2 pHit = r.origin + r.direction * outHit;
                centre = pHit;
                return(true);
            }
        }
        return(false);
    }
예제 #14
0
        public Rect2D GetBoundary(Point startPoint)
        {
            switch (Type)
            {
            case SegmentType.StartPoint:
                return(new Rect2D(Parameters[0], Parameters[1], 0, 0));

            case SegmentType.Line:
                return(new Rect2D(new Point(startPoint.X, startPoint.Y), new Point(Parameters[0], Parameters[1])));

            case SegmentType.CircArc3Points:
            {
                var arc = new Arc2D(startPoint, new Point(Parameters[2], Parameters[3]), new Point(Parameters[0], Parameters[1]));
                return(arc.GetBoundary());
            }

            default:
                throw new NotImplementedException();
            }
        }
예제 #15
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         Vector2D vec1   = new Vector2D();
         Vector2D vec2   = new Vector2D();
         Point2D  center = new Point2D(2003.4945, 1103.6469);
         Point2D  start  = new Point2D(2494.6048, 982.6129);
         Point2D  end    = new Point2D(1499.1729, 1142.3536);
         Debug.WriteLine("distance between p1 p2 is : " + center.GetDistanceTo(start).ToString());
         Debug.WriteLine("distance between p2 p3 is : " + end.GetDistanceTo(start).ToString());
         Arc2D arc1 = new Arc2D(center, start, end);
         vec1 = center.GetVector2DTo(start);
         vec2 = center.GetVector2DTo(end);
     }
     catch (System.Exception ex)
     {
         Debug.WriteLine(ex.Message);
     }
 }
예제 #16
0
    /// <summary>
    /// Arc2DHandle.
    /// </summary>
    /// <returns>Returns the center position used to draw an Arc.</returns>
    /// <param name="p1">Point 1.</param>
    /// <param name="p2">Point 2.</param>
    /// <param name="centre">Centre.</param>
    /// <param name="wasHit">The tracking for whether the handle was selected.</param>
    static Arc2D DrawArc2DHandle(Arc2D arc, Vector2 centre, int hash, Color lineColor, Color arcColor, Event e)
    {
        Vector3[] positions = new Vector3[20];
        for (int i = 0; i < 20; i++)
        {
            positions [i] = arc.GetPosition(i / 19f);
            positions [i] = positions [i];
        }
        Handles.color = arcColor;
        Handles.DrawAAPolyLine(positions);
        Handles.color = lineColor;
        Handles.DrawLine(arc.centre, arc.p1);
        Handles.DrawLine(arc.centre, arc.p2);
        Handles.DrawDottedLine(arc.centre, centre, 5f);
        float size = HandleUtility.GetHandleSize(centre) * 0.1f;

        if (e.type == EventType.Layout)
        {
            HandleUtility.AddControl(hash, HandleUtility.DistanceToRectangle(Handles.matrix.MultiplyPoint(centre), Quaternion.identity, size));
        }
        Handles.RectangleHandleCap(hash, centre, Quaternion.identity, size, EventType.Repaint);
        return(arc);
    }
예제 #17
0
        public Profile2D GetClosedProfile()
        {
            var cerchio = new Arc2D
            {
                Center    = new Point2D(CentroX, CentroY),
                Radius    = Raggio,
                ClockWise = false,
                Start     = { X = CentroX + Raggio },
                End       = { X = CentroX + Raggio },
            };


            cerchio.Start.Y = CentroY;
            cerchio.End.Y   = CentroY;


            var profile2D = new Profile2D();

            profile2D.AddEntity(cerchio);

            cerchio.PlotStyle = EnumPlotStyle.Element;
            return(profile2D);
        }
예제 #18
0
 public static bool equal(Arc2D a1, Arc2D a2)
 {
   if (a1 == null)
     return a2 == null;
   else
     return a2 != null && ((RectangularShape) a1).getFrame().equals((object) ((RectangularShape) a2).getFrame()) && (a1.getAngleStart() == a2.getAngleStart() && a1.getAngleExtent() == a2.getAngleExtent()) && a1.getArcType() == a2.getArcType();
 }
예제 #19
0
 private static IEnumerable <IEntity2D> CreateChamfer(Arc2D arc, Arc2D arc2, double radiusValue, out bool radiusSuccess)
 {
     radiusSuccess = false;
     return(null);
 }
예제 #20
0
        private static IEnumerable <IEntity2D> CreateRadius(Line2D geometry, Line2D line, double radiusValue, out bool radiusSuccess)
        {
            var l2P1 = line.Start;
            var l2P2 = line.End;

            var l1A = GeometryHelper.GetAngle(geometry.End, geometry.Start);
            var l2A = GeometryHelper.GetAngle(l2P1, l2P2);

            var teoricPnt = geometry.End;

            //var angleResult = GetAverageAngle(l1A, l2A);

            /// codice preso da internet , non ci ho pensato su molto forse buggy
            double difference = l2A - l1A;

            while (difference < -Math.PI)
            {
                difference += Math.PI * 2;
            }
            while (difference > Math.PI)
            {
                difference -= Math.PI * 2;
            }

            var angleAtRadius = Math.PI - Math.Abs(difference);

            var distanceTrimmed = GetDistanceTrimmedByRadius(angleAtRadius / 2, radiusValue);

            var puntoFinaleLinea = GeometryHelper.GetPointAtDistance(geometry.Start, geometry.End, distanceTrimmed, false);

            var puntoFinaleRaggio = GeometryHelper.GetPointAtDistance(l2P1, l2P2, distanceTrimmed, true);

            if (puntoFinaleLinea == null || puntoFinaleRaggio == null)
            {
                radiusSuccess = false;
                return(null);
            }

            var lineWithRadius = new List <IEntity2D>();

            geometry.End = puntoFinaleLinea;
            line.Start   = puntoFinaleRaggio;

            var raccordo = new Arc2D {
                Start = new Point2D(puntoFinaleLinea), End = new Point2D(puntoFinaleRaggio), Radius = radiusValue
            };

            raccordo.Center = CalcCenterRadius(geometry.Start, teoricPnt, l2P2, radiusValue);


            raccordo.ClockWise = GeometryHelper.IsClockWise(puntoFinaleLinea, puntoFinaleRaggio, raccordo.Center);

            // raccordo.Center = RawArc2D.GetCenterFromTwoPointsAndRadius(geometry.Start, geometry.End,radiusValue, false);


            lineWithRadius.Add(geometry);
            lineWithRadius.Add(raccordo);

            foreach (var entity2D in lineWithRadius)
            {
                entity2D.PlotStyle = geometry.PlotStyle;
            }


            radiusSuccess = true;

            return(lineWithRadius);
        }
예제 #21
0
        /// <summary>
        /// Smusso fra arco - linea
        /// </summary>
        /// <param name="arc"></param>
        /// <param name="line2D"></param>
        /// <param name="chamferValue"></param>
        /// <param name="lineFirst"></param>
        /// <param name="chamferSuccess"></param>
        /// <returns></returns>
        public static IEnumerable <IEntity2D> ChamferEntity(Arc2D arc, Line2D line2D, double chamferValue, bool lineFirst, out bool chamferSuccess)
        {
            /*
             * Per trovare punto sulla cfr
             * - creo cerchio nel punto incontro con raggio == valore dello smusso
             * - per linea faccio uguale metodo linea linea
             *
             */

            Point2D intersectionPnt = null;

            if (lineFirst)
            {
                intersectionPnt = line2D.End;
            }
            else
            {
                intersectionPnt = arc.End;
            }

            //Point2D intersectionPnt = arc.Start;

            var startArcChamfer = GetInitChamferPointOnCfr(arc, intersectionPnt, chamferValue, lineFirst);

            var flagEnd = !lineFirst;

            var puntoLineaRslt = GeometryHelper.GetPointAtDistance(line2D.Start, line2D.End, chamferValue, flagEnd);

            if (puntoLineaRslt == null)
            {
                chamferSuccess = false;
                return(null);
            }

            var lineChamfered = new List <IEntity2D>();

            if (lineFirst)
            {
                line2D.End = puntoLineaRslt;
                arc.Start  = startArcChamfer;

                var chamfer = new Line2D {
                    Start = new Point2D(puntoLineaRslt), End = new Point2D(startArcChamfer)
                };
                lineChamfered.Add(line2D);
                lineChamfered.Add(chamfer);

                foreach (var entity2D in lineChamfered)
                {
                    entity2D.PlotStyle = line2D.PlotStyle;
                }
            }
            else
            {
                line2D.Start = puntoLineaRslt;
                arc.End      = startArcChamfer;

                var chamfer = new Line2D {
                    Start = new Point2D(startArcChamfer), End = new Point2D(puntoLineaRslt)
                };
                lineChamfered.Add(arc);
                lineChamfered.Add(chamfer);

                foreach (var entity2D in lineChamfered)
                {
                    entity2D.PlotStyle = arc.PlotStyle;
                }
            }

            chamferSuccess = true;
            return(lineChamfered);
        }
예제 #22
0
파일: Arc.cs 프로젝트: pfjgeng/Tida.CAD
 public Arc(Arc2D arc2D)
 {
     Arc2D = arc2D ?? throw new ArgumentNullException(nameof(arc2D));
     Pen   = LinePen;
 }
예제 #23
0
        /// <summary>
        /// Funzione usata per disegnare linee
        /// </summary>
        void PlotElement(Arc2D arc)
        {
            // se l'arco è definito solamente dal raggio prendo cerchio
            // è fare metodo per definire meglio il raggio dell'elemento da stampar..

            if (arc.Start == null && arc.End == null && arc.Radius > 0 && arc.Center != null)
            {
                var el = new Ellipse {
                    Height = NormX(arc.Radius, arc.Radius), Width = NormX(Width, arc.Radius / 2)
                };

                el.SetValue(LeftProperty, NormX(arc.Center.X, arc.Radius / 2));
                el.SetValue(TopProperty, NormY(arc.Center.Y, arc.Radius / 2));

                //todo: il settaggio rtaggrupparlo con metodo setHiglight(ientity2d ent, graphicelemtne graphic element)

                switch (arc.PlotStyle)
                {
                default:
                case EnumPlotStyle.Element:
                {
                    el.Stroke          = Brushes.Green;
                    el.StrokeThickness = 1.5;
                } break;

                case EnumPlotStyle.SelectedElement:
                {
                    el.Stroke          = Brushes.Red;
                    el.StrokeThickness = 2.5;
                } break;

                case EnumPlotStyle.Path:
                {
                    el.Stroke          = Brushes.OrangeRed;
                    el.StrokeThickness = .3;
                } break;

                case EnumPlotStyle.SelectedPath:
                {
                    el.Stroke          = Brushes.Gainsboro;
                    el.StrokeThickness = .5;
                } break;
                }

                Children.Add(el);

                return;
            }

            // todo : controllare presenza 3 punti

            var center = arc.Center;

            var startAngle = GetPositiveAngle(arc.Start.X - center.X, arc.Start.Y - center.Y);

            var endAngle = GetPositiveAngle(arc.End.X - center.X, arc.End.Y - center.Y);

            var radius = arc.Radius;

            var myPathFigure = new PathFigure();

            myPathFigure.StartPoint = new Point(NormX(arc.Start.X, 0), NormY(arc.Start.Y, 0));

            var myPathSegmentCollection = new PathSegmentCollection();


            if (arc.ClockWise)
            {
                if (startAngle < endAngle)
                {
                    startAngle += 2 * Math.PI;
                }

                for (var i = startAngle; i >= endAngle; i -= .05)
                {
                    var myLineSegment = new LineSegment();
                    var x             = (Math.Cos(i) * radius) + center.X;
                    var y             = (Math.Sin(i) * radius) + center.Y;

                    myLineSegment.Point = new Point(NormX(x, 0), NormY(y, 0));
                    myPathSegmentCollection.Add(myLineSegment);
                }
            }
            else
            {
                if (endAngle < startAngle)
                {
                    endAngle += 2 * Math.PI;
                }

                if (endAngle > startAngle)
                {
                    for (var i = startAngle; i <= endAngle; i += .05)
                    {
                        var myLineSegment = new LineSegment();
                        var x             = (Math.Cos(i) * radius) + center.X;
                        var y             = (Math.Sin(i) * radius) + center.Y;

                        myLineSegment.Point = new Point(NormX(x, 0), NormY(y, 0));
                        myPathSegmentCollection.Add(myLineSegment);
                    }
                }
            }



            myPathFigure.Segments = myPathSegmentCollection;

            var myPathFigureCollection = new PathFigureCollection {
                myPathFigure
            };

            var myPathGeometry = new PathGeometry {
                Figures = myPathFigureCollection
            };

            var myPath = new Path {
                Data = myPathGeometry
            };

            switch (arc.PlotStyle)
            {
            default:
            case EnumPlotStyle.Element:
            {
                myPath.Stroke          = Brushes.Green;
                myPath.StrokeThickness = 1.5;
            } break;

            case EnumPlotStyle.SelectedElement:
            {
                myPath.Stroke          = Brushes.Red;
                myPath.StrokeThickness = 2.5;
            } break;

            case EnumPlotStyle.Path:
            {
                myPath.Stroke          = Brushes.OrangeRed;
                myPath.StrokeThickness = .3;
            } break;

            case EnumPlotStyle.SelectedPath:
            {
                myPath.Stroke          = Brushes.Gainsboro;
                myPath.StrokeThickness = .5;
            } break;
            }

            Children.Add(myPath);
        }
예제 #24
0
        /// <summary>
        /// Detects arcs on gasket image
        /// </summary>
        private static void DetectArcs(Image gasketImage, out Arc2D[] detectedArcs, Segment2D[] conntectingSegments,
                                       CoordinateSystem2D localSystem)
        {
            using (ArcFittingMap
                   arcMap1 = new ArcFittingMap(),
                   arcMap2 = new ArcFittingMap())
            {
                //public static void CreateArcFittingMap
                //(
                //    AvlNet.ImageFormat inImageFormat,
                //    AvlNet.ArcFittingField inFittingField,
                //    AvlNet.CoordinateSystem2D? inFittingFieldAlignment,
                //    int inScanCount,
                //    int inScanWidth,
                //    AvlNet.InterpolationMethod inImageInterpolation,
                //    AvlNet.ArcFittingMap outFittingMap,
                //    IList<AvlNet.Segment2D> diagScanSegments,
                //    IList<AvlNet.Rectangle2D> diagSamplingAreas
                //)

                AVL.CreateArcFittingMap(new ImageFormat(gasketImage),
                                        new ArcFittingField(upperExpectedArc, 20.0f),
                                        localSystem,
                                        10, 5,
                                        InterpolationMethod.Bilinear,
                                        arcMap1);

                AVL.CreateArcFittingMap(new ImageFormat(gasketImage),
                                        new ArcFittingField(lowerExpectedArc, 20.0f),
                                        localSystem,
                                        10, 5,
                                        InterpolationMethod.Bilinear,
                                        arcMap2);

                Arc2D?upperArc, lowerArc;


                //public static void FitArcToEdges
                //(
                //    AvlNet.Image inImage,
                //    AvlNet.ArcFittingMap inFittingMap,
                //    AvlNet.EdgeScanParams inEdgeScanParams,
                //    AvlNet.Selection inEdgeSelection,
                //    AvlNet.LocalBlindness? inLocalBlindness,
                //    float inMaxIncompleteness,
                //    AvlNet.CircleFittingMethod inFittingMethod,
                //    AvlNet.MEstimator? inOutlierSuppression,
                //    out AvlNet.Arc2D? outArc,
                //    IList<AvlNet.Edge1D?> outEdges,
                //    INullable<AvlNet.Profile> outDeviationProfile,
                //    IList<AvlNet.Point2D> outInliers,
                //    IList<AvlNet.Profile> diagBrightnessProfiles,
                //    IList<AvlNet.Profile> diagResponseProfiles
                //)

                AVL.FitArcToEdges(gasketImage,
                                  arcMap1,
                                  scanParams,
                                  Selection.Best, 0.1f, CircleFittingMethod.GeometricLandau,
                                  out upperArc);

                AVL.FitArcToEdges(gasketImage,
                                  arcMap2,
                                  scanParams,
                                  Selection.Best, 0.1f, CircleFittingMethod.GeometricLandau,
                                  out lowerArc);

                if (upperArc.HasValue && lowerArc.HasValue)
                {
                    //mr:: 这里使用了 Value 属性来取值.
                    detectedArcs = new[] { upperArc.Value, lowerArc.Value };

                    conntectingSegments[1] = new Segment2D(detectedArcs[0].Center, detectedArcs[1].Center);
                }
                else
                {
                    detectedArcs = new Arc2D[0];
                }
            }
        }
예제 #25
0
        public static Arc2D[] CutRectangleFromArc(
            Vector2D rectOrigin,
            Vector2D rectDx,
            Vector2D rectDy,
            Arc2D arc)
        {
            Vector2D vector2D1 = rectOrigin;
            Vector2D vector2D2 = rectOrigin + rectDx;
            Vector2D vector2D3 = rectOrigin + rectDx + rectDy;
            Vector2D vector2D4 = rectOrigin + rectDy;

            Segment2D[] segment2DArray = new Segment2D[4] {
                new Segment2D(vector2D1.X, vector2D1.Y, vector2D2.X, vector2D2.Y), new Segment2D(vector2D2.X, vector2D2.Y, vector2D3.X, vector2D3.Y), new Segment2D(vector2D3.X, vector2D3.Y, vector2D4.X, vector2D4.Y), new Segment2D(vector2D4.X, vector2D4.Y, vector2D1.X, vector2D1.Y)
            };
            List <IntersectionUtil.Struct1> struct1List = new List <IntersectionUtil.Struct1>();

            for (int index = 0; index < segment2DArray.Length; ++index)
            {
                Segment2D line = segment2DArray[index];
                foreach (double intersectionAngle in IntersectionUtil.GetIntersectionAngles(line, arc))
                {
                    Vector2D delta        = line.GetDelta();
                    double   num          = intersectionAngle + System.Math.PI / 2.0;
                    Vector2D vector2D5    = new Vector2D(System.Math.Cos(num), System.Math.Sin(num));
                    bool     isStartOfCut = delta.X * vector2D5.Y - vector2D5.X * delta.Y > 0.0;
                    double   angle        = intersectionAngle - arc.StartAngle;
                    if (angle < 0.0)
                    {
                        angle += 2.0 * System.Math.PI;
                    }
                    struct1List.Add(new IntersectionUtil.Struct1(angle, isStartOfCut));
                }
            }
            if (struct1List.Count == 0)
            {
                Vector2D u       = (Vector2D)(arc.Center + arc.Radius * new Vector2D(System.Math.Cos(arc.StartAngle), System.Math.Sin(arc.StartAngle))) - rectOrigin;
                double   length1 = rectDx.GetLength();
                double   num1    = length1 * length1;
                double   length2 = rectDy.GetLength();
                double   num2    = length2 * length2;
                double   num3    = Vector2D.DotProduct(u, rectDx);
                double   num4    = Vector2D.DotProduct(u, rectDy);
                if (num3 >= 0.0 && num3 <= num1 && (num4 >= 0.0 && num4 <= num2))
                {
                    return(new Arc2D[0]);
                }
                return(new Arc2D[1] {
                    arc
                });
            }
            struct1List.Sort();
            IntersectionUtil.Struct1 struct1_1 = struct1List[0];
            IntersectionUtil.Struct1 struct1_2 = struct1List[struct1List.Count - 1];
            if (struct1_1.Angle != 0.0)
            {
                struct1List.Insert(0, new IntersectionUtil.Struct1(0.0, !struct1_1.IsStartOfCut));
            }
            double angle1 = arc.EndAngle - arc.StartAngle;

            if (angle1 < 0.0)
            {
                angle1 += 2.0 * System.Math.PI;
            }
            if (struct1_2.Angle != angle1)
            {
                struct1List.Add(new IntersectionUtil.Struct1(angle1, !struct1_2.IsStartOfCut));
            }
            List <Arc2D> arc2DList = new List <Arc2D>(3);

            for (int index = 0; index < struct1List.Count - 1; ++index)
            {
                IntersectionUtil.Struct1 struct1_3 = struct1List[index];
                IntersectionUtil.Struct1 struct1_4 = struct1List[index + 1];
                if (!struct1_3.IsStartOfCut && struct1_4.IsStartOfCut)
                {
                    double startAngle = arc.StartAngle + struct1_3.Angle;
                    if (startAngle >= 2.0 * System.Math.PI)
                    {
                        startAngle -= 2.0 * System.Math.PI;
                    }
                    double endAngle = arc.StartAngle + struct1_4.Angle;
                    if (endAngle >= 2.0 * System.Math.PI)
                    {
                        endAngle -= 2.0 * System.Math.PI;
                    }
                    if (startAngle != endAngle)
                    {
                        Arc2D arc2D = new Arc2D(arc.Center, arc.Radius, startAngle, endAngle);
                        arc2DList.Add(arc2D);
                    }
                }
            }
            return(arc2DList.ToArray());
        }