/// <summary> /// Construct ellipse from two conjugate diameters, and set /// Axis0 to the major axis and Axis1 to the minor axis. /// The algorithm was constructed from first principles. /// Also computes the squared lengths of the major and minor /// half axis. /// </summary> public static __et__ FromConjugateDiameters(__vt__ center, /*# if (d == 3) { */ __vt__ normal, /*# } */ __vt__ a, __vt__ b, out double major2, out double minor2) { var ab = __vt__.Dot(a, b); double a2 = a.LengthSquared, b2 = b.LengthSquared; if (ab.IsTiny()) { if (a2 >= b2) { major2 = a2; minor2 = b2; return(new __et__(center, /*# if (d == 3) { */ normal, /*# } */ a, b)); } else { major2 = b2; minor2 = a2; return(new __et__(center, /*# if (d == 3) { */ normal, /*# } */ b, a)); } } else { var t = 0.5 * Fun.Atan2(2 * ab, a2 - b2); double ct = Fun.Cos(t), st = Fun.Sin(t); __vt__ v0 = a * ct + b * st, v1 = b * ct - a * st; a2 = v0.LengthSquared; b2 = v1.LengthSquared; if (a2 >= b2) { major2 = a2; minor2 = b2; return(new __et__(center, /*# if (d == 3) { */ normal, /*# } */ v0, v1)); } else { major2 = b2; minor2 = a2; return(new __et__(center, /*# if (d == 3) { */ normal, /*# } */ v1, v0)); } } }
/// <summary> /// Get count points on the circumference of the ellipse. /// </summary> public __vt__[] GetPoints(int count) { var array = new __vt__[count]; var c = Center; ForEachVector(count, (i, v) => array[i] = c + v); return(array); }
public __et__(__vt__ center, /*# if (d == 3) { */ __vt__ normal, /*# } */ __vt__ axis0, __vt__ axis1) { Center = center; //# if (d == 3) { Normal = normal; //# } Axis0 = axis0; Axis1 = axis1; }