public static bool equal(Ellipse2D e1, Ellipse2D e2)
 {
   if (e1 == null)
     return e2 == null;
   else
     return e2 != null && ((RectangularShape) e1).getFrame().equals((object) ((RectangularShape) e2).getFrame());
 }
Example #2
0
        /// <summary>
        /// Adds an Ellipse2D to the OCAF tree.
        /// </summary>
        /// <param name="ellipse"></param>
        /// <param name="ax2"></param>
        /// <returns></returns>
        private int AddToOcaf(Ellipse2D ellipse, OCgp_Ax2 ax2)
        {
            Node mainLabel = _document.Root;

            label = mainLabel.AddNewChild();
            return(UpdateElipsePosition(label, ellipse, ax2));
        }
Example #3
0
        /// <summary>
        /// 设定椭圆数据核心;
        /// </summary>
        /// <param name="ellipse2D"></param>
        private void SetEllipse2DCore(Ellipse2D ellipse2D)
        {
            if (ellipse2D == null)
            {
                throw new ArgumentNullException(nameof(ellipse2D));
            }

            _ellipse2D = ellipse2D;
            RaiseVisualChanged();
        }
        /// <summary>
        /// 将指定的<see cref="Ellipse2D"/>数据同步至UI;
        /// </summary>
        private void ApplyEllipse2DToEditors(Ellipse2D ellipse2D)
        {
            if (ellipse2D == null)
            {
                return;
            }

            positionVector2DEditor.Vector2D = ellipse2D.Center;
            txb_RadiusX.Text = ellipse2D.RadiusX.ToString();
            txb_RadiusY.Text = ellipse2D.RadiusY.ToString();
        }
Example #5
0
 internal EllipseIterator(Ellipse2D e, AffineTransform at)
 {
     this.x      = e.X;
     this.y      = e.Y;
     this.w      = e.Width;
     this.h      = e.Height;
     this.Affine = at;
     if (w < 0 || h < 0)
     {
         Index = 6;
     }
 }
Example #6
0
        static void Logo(Factory2D F, float X, float Y, float Height, float Fatness)
        {
            const double AngleOffset = 0.09;

            Ellipse2D LeftUpper = F.CreateEllipse(X, Y - Fatness / 2 + Height,
                                                  0, 0, Height / 2, Height, -3 * Math.PI / 2, -Math.PI / 2);

            Ellipse2D RightUpperUpper = F.CreateEllipse(X, Y - Fatness / 2 + Height,
                                                        0, 0, Height / 2 - Fatness, Height - Fatness, Math.PI / 2, Math.PI - AngleOffset);

            Ellipse2D RightUpperLower = F.CreateEllipse(X, Y - Fatness / 2 + Height,
                                                        0, 0, Height / 2 - Fatness, Height - Fatness, Math.PI + AngleOffset, 3 * Math.PI / 2);

            Ellipse2D LeftLower = F.CreateEllipse(X, Y + Fatness / 2 - Height,
                                                  0, 0, Height / 2 - Fatness, Height - Fatness, 3 * Math.PI / 2, Math.PI / 2);
            Ellipse2D RightLower = F.CreateEllipse(X, Y + Fatness / 2 - Height,
                                                   0, 0, Height / 2, Height, 3 * Math.PI / 2, Math.PI / 2);

            LeftUpper.EndPoint       = LeftLower.EndPoint;
            RightUpperLower.EndPoint = RightLower.EndPoint;

            Circle2D UpperCircle = F.CreateCircle(X, (Y + Height * 2) - Fatness, Fatness / 2, -Math.PI / 2, Math.PI / 2);

            UpperCircle.EndPoint   = LeftUpper.StartPoint;
            UpperCircle.StartPoint = RightUpperUpper.StartPoint;

            Circle2D LowerCircle = F.CreateCircle(X, (Y - Height * 2) + Fatness, Fatness / 2, Math.PI / 2, -Math.PI / 2);

            LowerCircle.StartPoint = LeftLower.StartPoint;
            LowerCircle.EndPoint   = RightLower.StartPoint;

            Point2D BarLowerStart = RightUpperLower.StartPoint;
            Line2D  BarLower      = F.CreateLine(BarLowerStart.GetPos().X, BarLowerStart.GetPos().Y,
                                                 BarLowerStart.GetPos().X + Height / 2, BarLowerStart.GetPos().Y);

            BarLower.StartPoint = BarLowerStart;

            Point2D BarUpperStart = RightUpperUpper.EndPoint;
            Line2D  BarUpper      = F.CreateLine(BarUpperStart.GetPos().X, BarUpperStart.GetPos().Y,
                                                 BarUpperStart.GetPos().X + Height / 2, BarUpperStart.GetPos().Y);

            BarUpper.StartPoint = BarUpperStart;

            double   UpperX    = BarUpper.EndPoint.GetPos().X;
            double   UpperY    = BarUpper.EndPoint.GetPos().Y;
            double   LowerY    = BarLower.EndPoint.GetPos().Y;
            double   R         = (UpperY - LowerY) / 2;
            Circle2D BarCircle = F.CreateCircle(UpperX, LowerY + R, R, -Math.PI / 2, Math.PI / 2);

            BarCircle.EndPoint   = BarUpper.EndPoint;
            BarCircle.StartPoint = BarLower.EndPoint;
        }
        public override IDualSurfaceCurve[] GetPlaneIntersection(PlaneSurface pl, double umin, double umax, double vmin, double vmax, double precision)
        {
            if (Precision.IsPerpendicular(pl.Normal, zAxis, false))
            {
                // two lines along the cylinder axis
                Plane               lower = new Plane(location, zAxis);
                GeoPoint2D          sp2d  = lower.Project(pl.Location);
                GeoVector2D         dir2d = lower.Project(pl.Normal).ToLeft();
                GeoPoint2D[]        ips   = Geometry.IntersectLC(sp2d, dir2d, GeoPoint2D.Origin, xAxis.Length);
                IDualSurfaceCurve[] res   = new IDualSurfaceCurve[ips.Length];
                for (int i = 0; i < ips.Length; i++)
                {
                    GeoPoint p   = lower.ToGlobal(ips[i]);
                    Line     l3d = Line.TwoPoints(p, p + zAxis);
                    res[i] = new DualSurfaceCurve(l3d, this, new Line2D(this.PositionOf(l3d.StartPoint), this.PositionOf(l3d.EndPoint)), pl, new Line2D(pl.PositionOf(l3d.StartPoint), pl.PositionOf(l3d.EndPoint)));
                }
                return(res);
            }
            else
            {
                // an ellipse
                GeoPoint2D[] cnts = pl.GetLineIntersection(location, zAxis);
                if (cnts.Length == 1)
                {   // there must be exactly one intersection
                    GeoPoint  cnt       = pl.PointAt(cnts[0]);
                    GeoVector minorAxis = pl.Normal ^ zAxis;
                    minorAxis.Length = xAxis.Length;
                    GeoVector majorAxis = minorAxis ^ pl.Normal;
                    Polynom   impl      = GetImplicitPolynomial();
                    Polynom   toSolve   = impl.Substitute(new Polynom(majorAxis.x, "u", cnt.x, ""), new Polynom(majorAxis.y, "u", cnt.y, ""), new Polynom(majorAxis.z, "u", cnt.z, ""));
                    double[]  roots     = toSolve.Roots();
                    // there must be two roots
                    majorAxis = roots[0] * majorAxis;

                    Ellipse elli = Ellipse.Construct();
                    elli.SetEllipseCenterAxis(cnt, majorAxis, minorAxis);

                    GeoPoint2D[] fpnts = new GeoPoint2D[5];
                    for (int i = 0; i < 5; i++)
                    {
                        fpnts[i] = PositionOf(elli.PointAt(i / 6.0));
                    }
                    Ellipse2D e2d = Ellipse2D.FromFivePoints(fpnts); // there should be a better way to calculate the 2d ellipse, but the following is wrong:
                    // Ellipse2D e2d = new Ellipse2D(GeoPoint2D.Origin, PositionOf(cnt + majorAxis).ToVector(), PositionOf(cnt + minorAxis).ToVector());
                    // and principal axis doesn't yield the correct result either
                    // Geometry.PrincipalAxis(PositionOf(cnt + majorAxis).ToVector(), PositionOf(cnt + minorAxis).ToVector(), out GeoVector2D maj, out GeoVector2D min);
                    return(new IDualSurfaceCurve[] { new DualSurfaceCurve(elli, this, e2d, pl, pl.GetProjectedCurve(elli, 0.0)) });
                }
            }
            return(new IDualSurfaceCurve[0]);
        }
Example #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));
 }
Example #9
0
        private void OnMouseMove3dAction(Mouse3dPosition point)
        {
            // Drawing an ellipse realtime needs one point in the list
            if (_points.Count != 1)
            {
                return;
            }

            Double xMin = _points[0].X();
            Double yMin = _points[0].Y();

            double majorRadius = Math.Abs(point.Point.X() - xMin);
            double minorRadius = Math.Abs(point.Point.Y() - yMin);

            // The OCC requires the minor radius to be higher than 0
            if ((majorRadius < 0.01) || (minorRadius < 0.01))
            {
                return;
            }

            // The OCC ellipse requires the minor radius to be smaller than the major radius
            if (minorRadius > majorRadius)
            {
                double aux = majorRadius;
                majorRadius = minorRadius;
                minorRadius = aux;
            }

            try
            {
                // Build/regenerate the ellipse with the new coordinates
                if (_ellipse == null)
                {
                    _ellipse = new Ellipse2D(Context2d, xMin, yMin, majorRadius, minorRadius, 0);
                }
                else
                {
                    _ellipse.SetProperties(xMin, yMin, majorRadius, minorRadius, 0);
                }

                _ellipse.Display(true);
            }
            catch (Exception ex)
            {
                string message = "Exception on creating eclipse (logged): " + ex.Message;
                MessageBox.Show(message);
                log.Debug(message);
            }
        }
Example #10
0
            public void erstelleEllipseSkizze(double dA, double dB)
            {//cc.erstelleLprofilSkizze   (dgroßHlprofil, dgroßBlprofil, dkleinHlprofil, dkleinBlprofil);
                Factory2D fact2D = hsp_catiaProfil.OpenEdition();

                // Skizze umbenennen
                hsp_catiaProfil.set_Name("Ellipse");

                // Eckpunkte erstellen

                double dStartpunktx = 0;
                double dStartpunkty = 0;

                Ellipse2D ellipse2D = fact2D.CreateClosedEllipse(dStartpunktx, dStartpunkty, dStartpunktx, dStartpunkty, dA, dB);

                hsp_catiaProfil.CloseEdition();

                hsp_catiaPart.Part.Update();
            }
Example #11
0
        protected override void OnMouseDown(MouseDownEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            var thisPosition = e.Position;

            //若上次点击位置为空,则记录点击位置;
            if (MousePositionTracker.LastMouseDownPosition == null)
            {
                if (thisPosition.IsAlmostEqualTo(Ellipse2D.Center))
                {
                    MousePositionTracker.LastMouseDownPosition = thisPosition;
                }
                else if (thisPosition.IsAlmostEqualTo(Ellipse2D.GetTopPoint()) ||
                         thisPosition.IsAlmostEqualTo(Ellipse2D.GetBottomPoint()) ||
                         thisPosition.IsAlmostEqualTo(Ellipse2D.GetLeftPoint()) ||
                         thisPosition.IsAlmostEqualTo(Ellipse2D.GetRightPoint()))
                {
                    MousePositionTracker.LastMouseDownPosition = thisPosition;
                }
                else
                {
                    return;
                }

                e.Handled = true;
            }
            //否则将应用更改;
            else if (MousePositionTracker.CurrentHoverPosition != null)
            {
                var newEllipse = GetPreviewEllipse2D();
                if (newEllipse != null)
                {
                    Ellipse2D = newEllipse;
                }

                MousePositionTracker.Reset(true);

                e.Handled = true;
            }
        }
Example #12
0
        /// <summary>
        /// 当某个位置在点附近(以视图为准)时,返回点的绝对位置;
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="position"></param>
        /// <param name="canvasContext"></param>
        /// <returns></returns>
        protected override ISnapShape MatchSnapShape(PointBase point, Vector2D position, ICanvasContext canvasContext)
        {
            if (position == null)
            {
                throw new ArgumentNullException(nameof(position));
            }


            var screenPosition      = canvasContext.CanvasProxy.ToScreen(position);
            var pointScreenPosition = canvasContext.CanvasProxy.ToScreen(point.Position);
            var ellipse             = new Ellipse2D(pointScreenPosition, point.ScreenRadius, point.ScreenRadius);

            if (ellipse.Contains(screenPosition))
            {
                return(new StandardSnapPoint(point.Position));
            }

            return(null);
        }
Example #13
0
        /// <summary>
        /// 绘制椭圆(圆);
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="brush"></param>
        /// <param name="pen"></param>
        /// <param name="ellipse2D"></param>
        public static void DrawEllipse(this ICanvas canvas, Brush brush, Pen pen, Ellipse2D ellipse2D)
        {
            if (canvas == null)
            {
                throw new ArgumentNullException(nameof(canvas));
            }


            if (ellipse2D == null)
            {
                throw new ArgumentNullException(nameof(ellipse2D));
            }

            canvas.DrawEllipse(
                brush,
                pen,
                ellipse2D.Center,
                ellipse2D.RadiusX,
                ellipse2D.RadiusY
                );
        }
Example #14
0
        private void RefreshEllipse2D()
        {
            if (_ellipse2DRefreshing)
            {
                return;
            }

            _ellipse2DRefreshing = true;
            var newEllipse2D = GetInputEllipse2D();

            if (newEllipse2D != null)
            {
                Ellipse2D = newEllipse2D;
                Ellipse2DChanged?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                ApplyEllipse2DToEditors(Ellipse2D);
            }

            _ellipse2DRefreshing = false;
        }
Example #15
0
        int UpdateElipsePosition(Node label, Ellipse2D ellipse, OCgp_Ax2 ax2)
        {
            label.Update <StringInterpreter>().Value = DisplayedShapeNames.Ellipse;
            FunctionInterpreter elipseFunction = label.Update <FunctionInterpreter>();

            elipseFunction.Name = "Ellipse";

            elipseFunction.BeginUpdate();
            // Create the data structure : Set the dimensions, position and name attributes
            elipseFunction.Dependency.Child(1).Geometry = GeomUtils.VertexToPnt(ellipse.GetEllipseCenter(), ax2);
            // Add the major radius
            elipseFunction.Dependency.Child(2).Real = ellipse.GetMajorRadius();
            // Add the minor radius
            elipseFunction.Dependency.Child(3).Real = ellipse.GetMinorRadius();
            // Add angle
            elipseFunction.Dependency.Child(4).Real = ellipse.GetAngle();

            if (elipseFunction.Execute() != 0)
            {
                // TODO: Handle the error
            }

            return(0);
        }
Example #16
0
 public void setUp()
 {
     center      = new Point2D(12.0d, 14.0d);
     testEllipse = new Ellipse2D(center, 10.0d, 5.0d);
     zeroPoint   = new Point2D(0.0d, 0.0d);
 }
Example #17
0
        public void testRayCast()
        {
            // static tests
            Assert.AreEqual(double.PositiveInfinity, testEllipse.rayCast(new Ray2D(0.0d, 0.0d, 0.0d, 2.0d)), 0.000005d);
            Assert.AreEqual(2.0d, testEllipse.rayCast(new Ray2D(0.0d, 14.0d, 12.0d, 14.0d)), 0.000005d);

            // serial tests
            Ellipse2D randomEllipse;
            Point2D   randomPointOnEllipse;
            Point2D   randomPoint;
            double    currentXRadius;
            double    currentYRadius;
            double    xvalue;
            double    yvalue;
            double    randomAngle;
            int       sector;
            int       counter = 1000;

            do
            {
                randomEllipse  = new Ellipse2D(new Point2D(Util.generateRandomDoubleBetween(-500.0d, 500.0d), Util.generateRandomDoubleBetween(-500.0d, 500.0d)), Util.generateRandomDoubleBetween(0.0d, 200.0d), Util.generateRandomDoubleBetween(0.0d, 200.0d));
                currentXRadius = randomEllipse.getHorizontalLength();
                currentYRadius = randomEllipse.getVerticalLength();
                xvalue         = Util.generateRandomDoubleBetween(0.0d, currentXRadius);
                yvalue         = (currentYRadius * System.Math.Sqrt(currentXRadius * currentXRadius - xvalue * xvalue)) / currentXRadius;
                sector         = Util.randomNumberBetween(1, 4);
                switch (sector)
                {
                case 2:
                {
                    yvalue      = -yvalue;
                    randomPoint = new Point2D(Util.generateRandomDoubleBetween(randomEllipse.getCenter().getX() + xvalue, 1000.0d), Util.generateRandomDoubleBetween(-1000.0d, randomEllipse.getCenter().getY() + yvalue));
                    break;
                }

                case 3:
                {
                    xvalue      = -xvalue;
                    yvalue      = -yvalue;
                    randomPoint = new Point2D(Util.generateRandomDoubleBetween(-1000.0d, randomEllipse.getCenter().getX() + xvalue), Util.generateRandomDoubleBetween(-1000.0d, randomEllipse.getCenter().getY() + yvalue));
                    break;
                }

                case 4:
                {
                    xvalue      = -xvalue;
                    randomPoint = new Point2D(Util.generateRandomDoubleBetween(-1000.0d, randomEllipse.getCenter().getX() + xvalue), Util.generateRandomDoubleBetween(randomEllipse.getCenter().getY() + yvalue, 1000.0d));
                    break;
                }

                default:
                {
                    randomPoint = new Point2D(Util.generateRandomDoubleBetween(randomEllipse.getCenter().getX() + xvalue, 1000.0d), Util.generateRandomDoubleBetween(randomEllipse.getCenter().getY() + yvalue, 1000.0d));
                    break;
                }
                }
                randomPointOnEllipse = new Point2D(randomEllipse.getCenter().getX() + xvalue, randomEllipse.getCenter().getY() + yvalue);

                randomAngle          = Util.generateRandomDoubleBetween(-System.Math.PI / 2, System.Math.PI / 2);
                randomEllipse        = (Ellipse2D)(randomEllipse.transform(TransformMatrix2D.rotate(randomAngle)));
                randomPoint          = TransformMatrix2D.rotate(randomAngle).multiply(randomPoint);
                randomPointOnEllipse = TransformMatrix2D.rotate(randomAngle).multiply(randomPointOnEllipse);
                // System.Console.Writef("RayCast No. %d: Ellipse at (%.2f,%.2f), radii: (%.2f,%.2f). Rotation angle: %.2f, original angle: %.2f, point on ellipse: (%.2f,%.2f), outside point: (%.2f,%.2f), distance: %.2f.\n", 1000-counter, randomEllipse.getCenter().getX(), randomEllipse.getCenter().getY(), randomEllipse.getHorizontalLength(), randomEllipse.getVerticalLength(), randomEllipse.getAngle(), randomAngle, randomPointOnEllipse.getX(), randomPointOnEllipse.getY(), randomPoint.getX(), randomPoint.getY(), randomPoint.distance(randomPointOnEllipse));

                Assert.AreEqual(randomPoint.distance(randomPointOnEllipse), randomEllipse.rayCast(new Ray2D(randomPoint, randomPoint.vec(randomPointOnEllipse))), 0.000005d);
                counter -= 1;
            } while (counter > 0);
        }
Example #18
0
        public override ICurve2D GetProjectedCurve(ICurve curve, double precision)
        {
            ICurve2D dbg = base.GetProjectedCurve(curve, precision);

            if (curve is Ellipse elli)
            {   // a circle on the surface is projected to an ellipse in the uv plane
                GeoPoint2D[] positions = new GeoPoint2D[5];
                for (int i = 0; i < 5; i++)
                {
                    positions[i] = PositionOf(elli.PointAtParam(i * Math.PI * 2.0 / 6.0));
                }
                Ellipse2D elli2d = Ellipse2D.FromFivePoints(positions, true);
                double    prec   = precision;
                if (prec == 0)
                {
                    prec = Precision.eps;
                }
                if (elli2d == null)
                {
                    BoundingRect ext = new BoundingRect(positions);
                    GaussNewtonMinimizer.Ellipse2DFit(new ToIArray <GeoPoint2D>(positions), ext.GetCenter(), ext.Size / 2.0, ext.Size / 3.0, 0.0, prec, out elli2d);
                }
                else
                {
                    GaussNewtonMinimizer.Ellipse2DFit(new ToIArray <GeoPoint2D>(positions), elli2d.center, elli2d.majrad, elli2d.minrad, elli2d.majorAxis.Angle, prec, out elli2d);
                }
                //GeoPoint2D center = PositionOf(elli.Center);
                //GeoPoint2D maj = PositionOf(elli.Center + elli.MajorAxis);
                //GeoPoint2D min = PositionOf(elli.Center + elli.MinorAxis);
                //Geometry.PrincipalAxis(maj - center, min - center, out GeoVector2D majorAxis, out GeoVector2D minorAxis);
                //Ellipse2D elli2d = new Ellipse2D(center, maj - center, min - center);
                if (elli2d == null)
                {
                    return(base.GetProjectedCurve(curve, precision));
                }
                if (elli.IsArc)
                {
                    double       sp        = elli2d.PositionOf(PositionOf(elli.StartPoint));
                    double       ep        = elli2d.PositionOf(PositionOf(elli.EndPoint));
                    EllipseArc2D elliarc2d = elli2d.Trim(sp, ep) as EllipseArc2D;
                    // there must be a more sophisticated way to calculate the orientation and which part to use, but the following works:
                    double pm = elliarc2d.PositionOf(PositionOf(elli.PointAt(0.5)));
                    if (pm < 0 || pm > 1)
                    {
                        elliarc2d = elliarc2d.GetComplement();
                    }
                    pm = elliarc2d.PositionOf(PositionOf(elli.PointAt(0.1)));
                    if (pm > 0.5)
                    {
                        elliarc2d.Reverse();
                    }
                    return(elliarc2d);
                }
                else
                {   // get the correct orientation
                    double pos = elli2d.PositionOf(PositionOf(elli.PointAt(0.1)));
                    if (pos > 0.5)
                    {
                        elli2d.Reverse();
                    }
                    return(elli2d);
                }
            }
            return(base.GetProjectedCurve(curve, precision));
        }
Example #19
0
        public override ICurve2D GetProjectedCurve(ICurve curve, double precision)
        {
#if DEBUG
            if (id == 135 || id == 414)
            {
            }
#endif
            if (curve is Line line)
            {
                // this must be a line parallel to the axis, otherwise there are no lines on the cylinder
                // if it is an extremely small line not parallel to the axis, 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)
            {
                // the ellipse must be above the projection center of the 2d system
                // otherwise it is probably a hyperbola
                GeoPoint p1   = Geometry.DropPL(elli.Center + elli.MajorAxis, location, zAxis);
                GeoPoint p2   = Geometry.DropPL(elli.Center - elli.MajorAxis, location, zAxis);
                double   pos1 = Geometry.LinePar(location - zAxis, zAxis, p1);
                double   pos2 = Geometry.LinePar(location - zAxis, zAxis, p2);
                if (pos1 < 0 || pos2 < 0)
                {
                    return(base.GetProjectedCurve(curve, precision));
                }
                double d    = Geometry.DistPL(elli.Center, location, zAxis);
                double prec = (elli.MajorRadius + elli.MinorRadius) * 1e-6;
                // FromFivePoints for this case
                GeoPoint2D[] fp2d = new GeoPoint2D[5];
                double       n    = 5.0;
                if (elli.IsArc)
                {
                    n = 4;
                }
                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)
                {
                    if (elli.IsArc)
                    {
                        double       spar      = elli2d.PositionOf(PositionOf(elli.StartPoint));
                        double       epar      = elli2d.PositionOf(PositionOf(elli.EndPoint));
                        EllipseArc2D elliarc2d = elli2d.Trim(spar, epar) as EllipseArc2D;
                        // there must be a more sophisticated way to calculate the orientation and which part to use, but the following works:
                        double pm = elliarc2d.PositionOf(PositionOf(elli.PointAt(0.5)));
                        if (pm < 0 || pm > 1)
                        {
                            elliarc2d = elliarc2d.GetComplement();
                        }
                        pm = elliarc2d.PositionOf(PositionOf(elli.PointAt(0.1)));
                        if (pm > 0.5)
                        {
                            elliarc2d.Reverse();
                        }
                        return(elliarc2d);
                    }
                    else
                    {   // get the correct orientation
                        double pos = elli2d.PositionOf(PositionOf(elli.PointAt(0.1)));
                        if (pos > 0.5)
                        {
                            elli2d.Reverse();
                        }
                        return(elli2d);
                    }
                }
            }
            return(base.GetProjectedCurve(curve, precision));
        }
Example #20
0
        private void OnMouseClick3dAction(Mouse3dPosition point)
        {
            if (point.IsMouseDown == false)
            {
                AddToPointList(point.Point);
            }

            // Finished building the ellipse
            if (_points.Count < 2)
            {
                return;
            }

            try
            {
                double majorRadius = Math.Abs(_points[1].X() - _points[0].X());
                double minorRadius = Math.Abs(_points[1].Y() - _points[0].Y());

                // The OCC requires the minor radius to be higher than 0
                if ((majorRadius < 0.01) || (minorRadius < 0.01))
                {
                    _points.Clear();
                    return;
                }

                // The OCC ellipse requires the minor radius to be smaller than the major radius
                if (minorRadius > majorRadius)
                {
                    double aux = majorRadius;
                    majorRadius = minorRadius;
                    minorRadius = aux;
                }

                // Remove the realtime drawn ellipse
                Context2d.Erase(_ellipse, true, false);

                // Build the shape translated to the drawing plane
                var ellipse = new Ellipse2D(Context2d, _points[0].X(), _points[0].Y(), majorRadius, minorRadius, 0);

                // Add the ellipse to the OCAF data hierarchy and also display it
                _document.Transact();

                // Save the new shape into the Ocaf data structure
                int result = AddToOcaf(ellipse, Ax2);

                // Attach an integer attribute to L to memorize it's not displayed
                label.Update <IntegerInterpreter>().Value = (int)OcafObjectVisibility.ToBeDisplayed;

                _document.Commit("Draw circle");
                ellipse.Display(true);

                // Inform the listeners that a new shape was generated
                Inputs[ActionNames.SolverDrawerPipe].OnNotification("Draw Ellipse", ellipse);
                Inputs[ActionNames.EditDetectionPipe].OnNotification("Draw Ellipse", ellipse);

                // Clear the list and get ready for drawing a new ellipse
                _points.Clear();
            }
            catch (Exception ex)
            {
                string message = "Logged exception on creating ellipse: " + ex.Message;
                MessageBox.Show(message);
                log.Debug(message);
            }
        }
Example #21
0
 public Ellipse(Ellipse2D ellipse2D)
 {
     Ellipse2D = ellipse2D ?? throw new ArgumentNullException(nameof(ellipse2D));
 }
Example #22
0
 public CompassPlot(ValueDataset dataset)
 {
   CompassPlot compassPlot = this;
   this.drawBorder = false;
   this.roseHighlightPaint = (Paint) Color.black;
   this.rosePaint = (Paint) Color.yellow;
   this.roseCenterPaint = (Paint) Color.white;
   this.compassFont = new Font("Arial", 0, 10);
   this.datasets = new ValueDataset[1];
   this.seriesNeedle = new MeterNeedle[1];
   this.revolutionDistance = 360.0;
   if (dataset != null)
   {
     this.datasets[0] = dataset;
     dataset.addChangeListener((DatasetChangeListener) this);
   }
   this.circle1 = (Ellipse2D) new Ellipse2D.Double();
   this.circle2 = (Ellipse2D) new Ellipse2D.Double();
   this.rect1 = (Rectangle2D) new Rectangle2D.Double();
   this.setSeriesNeedle(0);
 }