Unknown model· unknown
from NVIDIA HelpSteer3 Preference
code a program in python to rotate a generic point in 3d a certain angle alpha along any…
- User
code a program in python to rotate a generic point in 3d a certain angle alpha along any line defined by two points
- Assistant
To rotate a point in 3D space around a given line by a certain angle, we can use the Rodrigues' rotation formula. Here's a Python implementation using NumPy:
pythonimport numpy as np from scipy.spatial.rotate import Rotation as R def rotate_point(point, line_point1, line_point2, angle): # Normalize the line vector line_vector = (line_point2 - line_point1) / np.linalg.norm(line_point2 - line_point1) # Create a rotation matrix using the axis-angle representation rotation_matrix = R.from_matrix(np.array([[line_vector[0], -line_vector[2], line_vector[1]], [line_vector[2], line_vector[0], -line_vector[1]], [-line_vector[1], line_vector[1], line_vector[0]]])) \ .as_matrix().dot(np.array([[np.cos(angle), -np.sin(angle), 0], [np.sin(angle), np.cos(angle), 0], [0, 0, 1]])) # Translate the rotation matrix so that the point is at the origin translation_matrix = np.eye(4) translation_matrix[0:3, 3] = -point rotation_matrix_with_translation = translation_matrix.dot(rotation_matrix).dot(translation_matrix) # Apply the rotation matrix to the point rotated_point = rotation_matrix_with_translation.dot(np.array([point[0], point[1], point[2], 1])) # Translate the point back to its original position rotated_point = rotated_point[0:3] + line_point1 return rotated_point # Example usage: point = np.array([1, 0, 0]) line_point1 = np.array([0, 0, 0]) line_point2 = np.array([0, 1, 0]) angle = np.pi / 4 rotated_point = rotate_point(point, line_point1, line_point2, angle) print(rotated_point)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.