getRectOnSphere function

Rect getRectOnSphere(
  1. Vector3 cartesian3D,
  2. Offset cartesian2D,
  3. Offset center,
  4. double radius,
  5. double zoomFactor,
  6. double pointSize,
)

Calculates the rectangle on the sphere corresponding to a 3D point and its 2D position on the screen.

Takes cartesian3D, cartesian2D, center, radius, zoomFactor, and pointSize as input parameters. cartesian3D is the 3D position of the point on the sphere. cartesian2D is the 2D position of the point on the screen. center is the center of the screen. radius is the radius of the sphere. zoomFactor is the zoom factor of the sphere. pointSize is the size of the point. Returns a Rect representing the rectangle on the sphere.

Implementation

Rect getRectOnSphere(Vector3 cartesian3D, Offset cartesian2D, Offset center,
    double radius, double zoomFactor, double pointSize) {
  // Calculate scale factors
  double scaleFactorX = getScaleFactor(
      cartesian2D, center, radius, true, cartesian3D.x, zoomFactor);
  double scaleFactorY = getScaleFactor(
      cartesian2D, center, radius, false, cartesian3D.x, zoomFactor);

  // Adjust width and height based on the position on the sphere
  double adjustedWidth =
      pointSize * scaleFactorX * 2 * cos(cartesian3D.y / radius);
  double adjustedHeight =
      pointSize * scaleFactorY * 2 * cos(cartesian3D.z / radius);

  // Draw an ellipse that represents a circle on the sphere
  return Rect.fromCenter(
    center: cartesian2D,
    width: adjustedWidth,
    height: adjustedHeight,
  );
}