Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- class ShapeMismatchError(Exception):
- pass
- def convert_from_sphere(
- distances: np.ndarray,
- azimuth: np.ndarray,
- inclination: np.ndarray,
- ) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
- # ваш код
- if not (distances.shape == azimuth.shape ==inclination.shape):
- raise ShapeMismatchError
- abscissa = distances * np.sin(inclination) * np.cos(azimuth)
- ordinates = distances * np.sin(inclination) * np.sin(azimuth)
- applicates = distances * np.cos(inclination)
- return abscissa, ordinates, applicates
- def convert_to_sphere(
- abscissa: np.ndarray,
- ordinates: np.ndarray,
- applicates: np.ndarray,
- ) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
- # ваш код
- if not (abscissa.shape == ordinates.shape == applicates.shape):
- raise ShapeMismatchError
- distances = np.sqrt(abscissa**2 + ordinates**2 + applicates**2)
- azimuth = np.full(abscissa.shape, np.pi / 2)
- mask1 = abscissa != 0
- azimuth[mask1] = np.arctan(ordinates[mask1] / abscissa[mask1])
- mask2 = distances != 0
- inclination = np.zeros(abscissa.shape)
- inclination[mask2] = np.arccos(applicates[mask2] / distances[mask2])
- return distances, azimuth, inclination
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement