plane function

Point2 plane(
  1. Swing s,
  2. double x,
  3. double y
)

The plane radius and angle under a screen point (inverts onSwing, cone included).

Implementation

(double, double) plane(Swing s, double x, double y) {
  final c = math.cos(s.rot);
  final n = math.sin(s.rot);
  final dx = x - s.cx;
  final dy = y - s.cy;
  final lx = dx * c + dy * n;
  final ly = -dx * n + dy * c;
  if (s.k == 0.0) {
    return (hypot(lx, ly / s.sy), math.atan2(ly / s.sy, lx));
  }
  final m = ly + s.k * s.r;
  final a = s.sy * s.sy - s.k * s.k;
  final b = 2.0 * m * s.k;
  final cc = lx * lx * s.sy * s.sy + m * m;
  final r = (-b + math.sqrt(b * b + 4.0 * a * cc)) / (2.0 * a);
  return (r, math.atan2((m - s.k * r) / s.sy, lx));
}