示例#1
0
        public static Point2d[] EllipseEllipse(Ellipse2d el1, Ellipse2d el2)
        {
            //reduce this problem to a circle-ellipse problem by
            //rotating ellipse 1 down, scaling it to circle and then
            //rotate ellipse2 down.
            Transform2d tr = Transform2d.Rotate(-el1.Rotation) * Transform2d.Stretch(1.0, 1.0 / el1.Ratio);

            //dont modify originals:
            el1 = new Ellipse2d(el1);
            el2 = new Ellipse2d(el2);
            el1.Transform(tr);
            el2.Transform(tr);

            Point2d[] res = EllipseCircle(el2, new Circle2d(el1.X, el1.Y, el1.MajorRadius));

            if (res == null)
            {
                return(null);
            }

            Transform2d trinv = (tr).Inversed;

            for (int l = 0; l < res.Length; l++)
            {
                res[l] = res[l].GetTransformed(trinv);
            }

            return(res);
        }
示例#2
0
        public static Point2d[] HyperbolaEllipse(Hyperbola2d hyp, Ellipse2d elp)
        {
            //TODO: this is probably more stable intersecting hyperbola with unitcircle. Rewrite.

            Transform2d tr = hyp.ToStandardPosition;

            hyp = new Hyperbola2d(hyp);
            elp = new Ellipse2d(elp);
            hyp.Transform(tr);
            elp.Transform(tr);

            GeneralConic2d hcon = new GeneralConic2d(1, 0.0, -1 / (hyp.B * hyp.B), 0.0, 0.0, -1);

            Point2dSet pset = new Point2dSet();

            pset.AddRange(ConicConic(hcon, elp.ToGeneralConic()));
            pset.Transform(tr.Inversed);
            return(pset.ToArray());
        }
示例#3
0
        public static Point2d[] EllipseEllipse2(Ellipse2d elp1, Ellipse2d elp2)
        {
            //TODO: check if this is better than EllipseEllipse in stabillity and replace it or remove this function

            Transform2d tr = elp1.ToStandardPosition;

            elp2 = new Ellipse2d(elp2); //dont alter the original ellipse
            elp2.Transform(tr);

            elp1 = new Ellipse2d(elp1);
            elp1.Transform(tr);

            GeneralConic2d con1 = new GeneralConic2d(1.0, 0.0, 1 / (elp1.Ratio * elp1.Ratio), 0.0, 0.0, -1.0);
            GeneralConic2d con2 = elp2.ToGeneralConic(); // GeneralConic2d.FromEllipse(elp2);

            Point2dSet pset = new Point2dSet();

            pset.AddRange(ConicConic(con1, con2));
            pset.Transform(tr.Inversed);
            return(pset.ToArray());
        }
示例#4
0
        public static Point2d[] EllipseCircle(Ellipse2d el, Circle2d ci)
        {
            Transform2d tr = el.ToStandardPosition;

            ci = new Circle2d(ci); //dont modify original circle, but this copy
            ci.Transform(tr);

            double b = el.Ratio, b2 = b * b, b4 = b2 * b2;
            double i = ci.Center.X, i2 = i * i, i4 = i2 * i2;
            double j = ci.Center.Y, j2 = j * j, j4 = j2 * j2;
            double r = ci.Radius, r2 = r * r, r4 = r2 * r2;

            double x4 = b4 - 2 * b2 + 1;
            double x3 = 4 * b2 * i - 4 * i;
            double x2 = b2 * (2 * r2 + 2 * j2 - 2 * i2 + 2) - 2 * r2 + 2 * j2 + 6 * i2 - 2 * b4;
            double x1 = 4 * i * r2 - 4 * i * j2 - 4 * i * i * i - 4 * b2 * i;
            double x0 = r4 + (-2 * j2 - 2 * i2) * r2 + b2 * (-2 * r2 - 2 * j2 + 2 * i2) + j4 + 2 * i2 * j2 + i4 + b4;
            //double[] xs = RealPolynomial.SolveQuartic2(x4, x3, x2, x1, x0, 1e-30);

            RealPolynomial rp = new RealPolynomial(x4, x3, x2, x1, x0);

            double[] xs = rp.FindRoots(true);

            if (xs == null)
            {
                return(null);               //no intersections
            }
            Point2dSet resultset = new Point2dSet();

            foreach (double x in xs)
            {
                //test the two possible y:s to be solutions for this x
                double y = (1 - x * x) * b2;
                if (y < 0.0)
                {
                    continue;
                }
                y = Math.Sqrt(y);

                for (int t = 0; t < 2; t++)                                             //test booth y solutions...
                {
                    double err  = x * x + y * y / b2 - 1.0;                             //on ellipse
                    double err2 = MathUtil.Square(x - i) + MathUtil.Square(y - j) - r2; //on circle
                    if (MathUtil.IsZero(err, 1e-7) && MathUtil.IsZero(err2, MathUtil.Epsilon))
                    {
                        resultset.Add(new Point2d(x, y));
                    }

                    y = -y;  // ...by inverting y in second turn
                }
            }

            if (resultset.Count == 0)
            {
                return(null);
            }

            resultset.Transform(tr.Inversed); //back to original position

            return(resultset.ToArray());
        }
示例#5
0
 public Ellipse2d(Ellipse2d tocopy)
 {
     center    = tocopy.center;
     majoraxis = tocopy.majoraxis;
     sigratio  = tocopy.sigratio;
 }