import numpy as np
def rotate_point_by_pi(point, rotation_center):
"""
Rotate a point by π (180 degrees) around a rotation center.
Args:
point: 1D numpy array [x, y]
rotation_center: 1D numpy array [cx, cy]
Returns:
Rotated point as 1D numpy array [x', y']
"""
# For π rotation: new_point = 2 * center - original_point
return 2 * rotation_center - point
# Example usage:
point = np.array([3.0, 4.0])
rotation_center = np.array([1.0, 2.0])
rotated_point = rotate_point_by_pi(point, rotation_center)
print(f"Original point: {point}")
print(f"Rotation center: {rotation_center}")
print(f"Rotated point: {rotated_point}")
The formula 2 * rotation_center - point works because rotating by π around a center point (cx, cy) is equivalent to reflecting the point through that center. Mathematically, if you rotate point (x, y) by π around center (cx, cy), the result is (2cx - x, 2cy - y).
If you need a more general rotation function for any angle:
def rotate_point(point, rotation_center, angle):
"""
Rotate a point by given angle around a rotation center.
Args:
point: 1D numpy array [x, y]
rotation_center: 1D numpy array [cx, cy]
angle: rotation angle in radians
Returns:
Rotated point as 1D numpy array [x', y']
"""
# Translate to origin
translated = point - rotation_center
# Apply rotation matrix
cos_a, sin_a = np.cos(angle), np.sin(angle)
rotation_matrix = np.array([[cos_a, -sin_a],
[sin_a, cos_a]])
rotated = rotation_matrix @ translated
# Translate back
return rotated + rotation_center