i have 1d numpy array with coords on one point [x,y], and i want to rotate it by pi, i…
- User
i have 1d numpy array with coords on one point [x,y], and i want to rotate it by pi, i have a rotation point also
Assistant
You can rotate a point around another point by translating, rotating, and translating back. Here's how to do it:
import numpy as np def rotate_point(point, rotation_center, angle): # Translate point to origin translated = point - rotation_center # Create rotation matrix cos_angle = np.cos(angle) sin_angle = np.sin(angle) rotation_matrix = np.array([[cos_angle, -sin_angle], [sin_angle, cos_angle]]) # Apply rotation rotated = rotation_matrix @ translated # Translate back result = rotated + rotation_center return result # Example usage point = np.array([x, y]) # your point coordinates rotation_center = np.array([cx, cy]) # your rotation center angle = np.pi # rotate by pi radians (180 degrees) rotated_point = rotate_point(point, rotation_center, angle)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.