getScaleFactor function

double getScaleFactor(
  1. Offset point,
  2. Offset center,
  3. double radius,
  4. bool isXAxis,
  5. double zCoord,
  6. double zoomFactor,
)

Calculates the scale factor for a point on the sphere.

Takes point, center, radius, isXAxis, zCoord, and zoomFactor as input parameters. point is the 2D position of the point on the screen. center is the center of the screen. radius is the radius of the sphere. isXAxis indicates whether the point lies on the X-axis or Y-axis. zCoord is the Z-coordinate of the point in 3D space. zoomFactor is the zoom factor of the sphere. Returns the scale factor for the point.

Implementation

double getScaleFactor(Offset point, Offset center, double radius, bool isXAxis,
    double zCoord, double zoomFactor) {
  // Calculate distance from the point to the center for the specified axis
  double distance =
      isXAxis ? (point.dx - center.dx).abs() : (point.dy - center.dy).abs();

  // Normalize Z-coordinate relative to the radius and adjust for zoom factor
  double normalizedZ = (zCoord / radius).clamp(-1, 1) * zoomFactor;

  // Check if the point is behind the sphere (not visible)
  if (normalizedZ < 0) return 0;

  // Perspective scaling factor
  double perspectiveScaling = 0.5 + 0.5 * normalizedZ;

  // Calculate the scaling factor based on the distance and perspective
  double scaleFactor = max(0.6, 1 - distance / radius) * perspectiveScaling;

  return scaleFactor;
}