示例#1
0
        public Point2d[] Perpendicular(Point2d from)
        {
            double      i, j; //i,j is from-point in standard space
            Transform2d tr = ToStandardPosition;

            tr.Apply(from.X, from.Y, out i, out j, true);

            //cubic coefficients gotten from langarnge multiplier minimizing distance from i,j to curve
            double[] xs = RealPolynomial.SolveCubic2(-1, 0.0, j - 0.25, 0.25 * i);
            if (xs == null)
            {
                return(null);
            }

            Point2d[] res = new Point2d[xs.Length];
            tr = tr.Inversed;
            int respos = 0;

            foreach (double x in xs)
            {
                tr.Apply(x, x * x, out i, out j, true);
                res[respos++] = new Point2d(i, j);
            }

            return(res);
        }
示例#2
0
        public Point2d GetTransformed(Transform2d t)
        {
            double tx, ty;

            t.Apply(X, Y, out tx, out ty, true);
            return(new Point2d(tx, ty));
        }
示例#3
0
        public Vector2d GetTransformed(Transform2d t)
        {
            double tx, ty;

            t.Apply(X, Y, out tx, out ty, false);
            return(new Vector2d(tx, ty));
        }
示例#4
0
        public bool Contains(Point2d pt)
        {
            Transform2d tr = ToStandardPosition;
            double      i, j;

            tr.Apply(pt.X, pt.Y, out i, out j, true);

            double dy = i * i - j; //y of parabola in std. pos subtracted with point y

            return(dy <= 0.0);
        }
示例#5
0
        public static double[] ParabolaLineParamteric(Parabola2d pab, Line2d lin) //tested ok
        {
            double x1, y1, x2, y2;                                                //line points in parabola standard position

            Transform2d tr = pab.ToStandardPosition;                              //intersect line with y=x^2 => easier

            tr.Apply(lin.X1, lin.Y1, out x1, out y1, true);
            tr.Apply(lin.X2, lin.Y2, out x2, out y2, true);

            double dx = x2 - x1;
            double dy = y2 - y1;
            double c2 = -dx * dx;
            double c1 = dy - 2 * dx * x1;
            double c0 = y1 - x1 * x1;

            //y1-x1^2+t*(dy-2*dx*x1)-dx^2*t^2=0

            double[] ts = RealPolynomial.SolveQuadric(c2, c1, c0);

            return(ts);
        }
示例#6
0
        public static double[] HyperbolaLineParametric(Hyperbola2d hyp, Line2d lin)
        {
            // Computes intersection points with a hyperbola and a line
            // solved and created by Robert.P. 2013-02-11
            //
            // solution is created by transforming system to hyperbola standard position,
            // and then solving the system x^2/a^2-y^2/b^2-1=0 , x=x0+t*dx and y=y0+t*dy (note that a is 1 in std. pos.)

            Transform2d tr = hyp.ToStandardPosition;

            //extract standard spaced line
            double x0, y0, x1, y1, dx, dy, b = hyp.Ratio;

            tr.Apply(lin.X1, lin.Y1, out x0, out y0, true);
            tr.Apply(lin.X2, lin.Y2, out x1, out y1, true);
            dx = x1 - x0; dy = y1 - y0;

            double t2 = -dy * dy + b * b * dx * dx;
            double t1 = -2 * dy * y0 + 2 * b * b * dx * x0;
            double t0 = -y0 * y0 + b * b * x0 * x0 - b * b;

            return(RealPolynomial.SolveQuadric(t2, t1, t0, 0.0));
        }
示例#7
0
        public static Circle2d[] LinePointPoint(Line2d li, Point2d pt1, Point2d pt2)
        {
            // max two solutions
            // solution created by Robert.P. 2013-02-07

            List <Circle2d> res = null;

            // transform problem so that we have a vertical line thru origo which simplifies stuff a lot
            Transform2d toorg = Transform2d.Translate(-li.X1, -li.Y1) * Transform2d.Rotate(-li.Angle + MathUtil.Deg90);
            Transform2d fromorg = toorg.Inversed;
            double      i, j, k, l;

            toorg.Apply(pt1.X, pt1.Y, out i, out j, true);
            toorg.Apply(pt2.X, pt2.Y, out k, out l, true);


            double y2 = 2 * k - 2 * i;
            double y1 = 4 * i * l - 4 * j * k;
            double y0 = -2 * i * l * l - 2 * i * k * k + (2 * j * j + 2 * i * i) * k;

            double[] ys = RealPolynomial.SolveQuadric(y2, y1, y0);
            if (ys == null)
            {
                return(null); //no solutions
            }
            foreach (double y in ys)
            {
                double xx = (y * y - 2 * j * y + j * j + i * i) / (2 * i), yy = y; //TODO: what if vertical line
                double rad = Math.Abs(xx);

                fromorg.Apply(xx, yy, out xx, out yy, true);
                AddResult(ref res, xx, yy, rad);
            }


            return(MakeResult(res));
        }
示例#8
0
        /// <summary>
        /// Intersects a line with a conic that is in standard position, that is, not rotated and
        /// centered at 0,0
        /// </summary>
        /// <param name="con"></param>
        /// <param name="lin"></param>
        /// <returns>A list of parameters on line that is intersection points, or null if no intersections</returns>
        private static double[] ConicLineParametric(GeneralConic2d con, Line2d lin)
        {
            //We construct a matrix so that: conic is unrotated (B term=0) and line starts at origo and has length=1.0
            //This is to improve stabillity of the equation

            double invlen = 1.0 / lin.Length;

            if (double.IsInfinity(invlen))
            {
                return(null);    //zero length line does not intersect
            }
            Transform2d tr = Transform2d.Translate(-lin.X1, -lin.Y1) * Transform2d.Rotate(-con.Rotation) * Transform2d.Scale(invlen);

            GeneralConic2d c = new GeneralConic2d(con);  //copy for modification
            double         x1 = lin.X2, y1 = lin.Y2;

            c.Transform(tr);
            tr.Apply(x1, y1, out x1, out y1, true); //transformed line end


            double t2 = y1 * y1 * c.C + x1 * x1 * c.A;
            double t1 = y1 * c.E + x1 * c.D;
            double t0 = c.F;

            double[] ts = RealPolynomial.SolveQuadric(t2, t1, t0);

            return(ts);

            /*double dx=lin.DX;
             * double dy=lin.DY;
             * double x0=lin.X1;
             * double y0=lin.Y1;
             *
             * double t2=con.C*dy*dy+con.A*dx*dx;
             * double t1=2*con.C*dy*y0+2*con.A*dx*x0+dy*con.E+con.D*dx;
             * double t0=con.C*y0*y0+con.E*y0+con.A*x0*x0+con.D*x0+con.F;
             *
             * return RealPolynomial.SolveQuadric(t2, t1, t0, 1e-9);*/
        }