Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_cartesian_to_cylindrical():
expected = np.array(
[[0.7071, 45, 0.7071], [0.7071, -45, -0.7071]], dtype=np.float32)
data = np.array([[0.5, 0.5, 0.7071], [0.5, -0.5, -0.7071]])
result = np.zeros_like(expected)
radial, angular, height = cartesian_to_cylindrical(data)
result[:, 0] = radial
result[:, 1] = angular
result[:, 2] = height
assert np.all(np.isclose(result, expected))
expected[:, 1] = np.deg2rad(expected[:, 1])
radial, angular, height = cartesian_to_cylindrical(data, degrees=False)
result[:, 0] = radial
result[:, 1] = angular
result[:, 2] = height
assert np.all(np.isclose(result, expected))
expected = np.array(
[[0.7071, 45, 0.7071], [0.7071, -45, -0.7071]], dtype=np.float32)
data = np.array([[0.5, 0.5, 0.7071], [0.5, -0.5, -0.7071]])
result = np.zeros_like(expected)
radial, angular, height = cartesian_to_cylindrical(data)
result[:, 0] = radial
result[:, 1] = angular
result[:, 2] = height
assert np.all(np.isclose(result, expected))
expected[:, 1] = np.deg2rad(expected[:, 1])
radial, angular, height = cartesian_to_cylindrical(data, degrees=False)
result[:, 0] = radial
result[:, 1] = angular
result[:, 2] = height
assert np.all(np.isclose(result, expected))
def compute(self):
ro, phi, z = cartesian_to_cylindrical(
self.points, degrees=self.degrees)
self.to_be_added["ro"] = ro
self.to_be_added["phi"] = phi