getSpherePosition3D function
Vector3
getSpherePosition3D(
- GlobeCoordinates coordinates,
- double radius,
- double rotationY,
- 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) {
// radius += 10;
// 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)
Vector3 cartesian = Vector3(radius * cos(lat) * cos(lon),
radius * cos(lat) * sin(lon), radius * sin(lat));
// Create rotation matrices for X, Y, and Z axes
Matrix3 rotationMatrixY = Matrix3.rotationY(-rotationY);
Matrix3 rotationMatrixZ = Matrix3.rotationZ(-rotationZ);
// Apply the rotations
return rotationMatrixY.multiplied(rotationMatrixZ).transform(cartesian);
}