getSpherePosition3D function

Vector3 getSpherePosition3D(
  1. GlobeCoordinates coordinates,
  2. double radius,
  3. double rotationY,
  4. double rotationZ,
)

Calculates the 3D position of a point on a sphere.

Takes coordinates, radius, rotationY, and rotationZ as input parameters. coordinates is an instance of GlobeCoordinates containing the latitude and longitude of the point. radius is the radius of the sphere. rotationY and rotationZ are rotation angles around the Y and Z axes, respectively. Returns a Vector3 representing the 3D position of the point on the sphere.

Implementation

Vector3 getSpherePosition3D(GlobeCoordinates coordinates, double radius,
    double rotationY, double rotationZ) {
  // Convert latitude and longitude to radians
  double lat = degreesToRadians(coordinates.latitude);
  double lon = degreesToRadians(coordinates.longitude);

  // Convert spherical coordinates (lat, lon, radius) to Cartesian coordinates (x, y, z)
  // Standard spherical to cartesian conversion:
  // x = R * cos(lat) * cos(lon)
  // y = R * cos(lat) * sin(lon)
  // z = R * sin(lat)
  Vector3 cartesian = Vector3(
    radius * cos(lat) * cos(lon),
    radius * cos(lat) * sin(lon),
    radius * sin(lat),
  );

  // Apply rotations
  // Note: rotationY and rotationZ are in radians
  Matrix4 rotationMatrix = Matrix4.identity()
    ..rotateY(-rotationY)
    ..rotateZ(-rotationZ);

  return rotationMatrix.transform3(cartesian);
}