public override GeneralConic2d ToGeneralConic() { Transform2d tr = Transform2d.Scale(MajorRadius) * Transform2d.Rotate(Rotation) * Transform2d.Translate(center.X, center.Y); GeneralConic2d elcon = new GeneralConic2d(1, 0, 1.0 / (sigratio * sigratio), 0, 0, -1); //x^2+(1/b)^2-1=0 => unit ellipse elcon.Transform(tr); //transform conic to position of ellipse return(elcon); //TODO: optimize this function }
public override GeneralConic2d ToGeneralConic() { //TODO: test this function Transform2d tr = Transform2d.Scale(majoraxis.Length) * Transform2d.Rotate(Rotation) * Transform2d.Translate(center.X, center.Y); GeneralConic2d hypcon = new GeneralConic2d(1, 0, -1.0 / (ratio * ratio), 0, 0, -1); //x^2-(y/b)^2-1=0 => unit hypcon.Transform(tr); return(hypcon); //TODO: optimize this function }
/// <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);*/ }