toCylindrical method
Converts the Vector from Cartesian to Cylindrical coordinates.
Returns a list of doubles [rho, phi, z] where:
- rho is the radial distance from the z-axis
- phi is the azimuth (angle from the x-axis in the xy-plane, in range
[0, 2*pi]) - z is the height along the z-axis
Example:
Vector v = Vector.fromList([1, 1, 1]);
print(v.toCylindrical());
// Output: [1.4142135623730951, 0.7853981633974483, 1]
Implementation
List toCylindrical() {
if (length != 3) {
throw Exception(
"Vector must be 3D for conversion to Cylindrical coordinates");
}
dynamic x = _data[0];
dynamic y = _data[1];
dynamic z = _data[2];
dynamic rho = math.sqrt(x * x + y * y);
dynamic phi = math.atan2(y, x);
return [rho, phi, z];
}