toCylindrical method

List<double> toCylindrical()

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<double> toCylindrical() {
  if (length != 3) {
    throw Exception(
        "Vector must be 3D for conversion to Cylindrical coordinates");
  }
  double x = _data[0].toDouble();
  double y = _data[1].toDouble();
  double z = _data[2].toDouble();
  double rho = math.sqrt(x * x + y * y);
  double phi = math.atan2(y, x);
  return [rho, phi, z];
}