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 line defined by two points, you can use the Rodrigues' rotation formula. Here's a Python function that implements this formula:
pythonimport numpy as np def rotate_point(point, line_point1, line_point2, angle): # Convert angle from degrees to radians angle = np.radians(angle) # Normalize the line vector line_vector = np.subtract(line_point2, line_point1) line_vector = line_vector / np.linalg.norm(line_vector) # Create a rotation matrix using Rodrigues' rotation formula a = np.cos(angle / 2) b, c, d = -line_vector * np.sin(angle / 2) aa, bb, cc, dd = a * a, b * b, c * c, d * d bc, ad, ac, ab, bd, cd = b * c, a * d, a * c, a * b, b * d, c * d rotation_matrix = np.array([ [aa + bb - cc - dd, 2 * (bc + ad), 2 * (bd - ac)], [2 * (bc - ad), aa + cc - bb - dd, 2 * (cd + ab)], [2 * (bd + ac), 2 * (cd - ab), aa + dd - bb - cc] ]) # Translate the point to the origin, apply the rotation, and translate back translated_point = np.subtract(point, line_point1) rotated_point = np.dot(rotation_matrix, translated_point) rotated_point = np.add(rotated_point, line_point1) return rotated_pointThis function takes a point to rotate, two points defining the rotation line, and an angle of rotation in degrees. It returns the rotated point.
Here's an example of how to use this function:
pythonpoint = np.array([1, 0, 0]) line_point1 = np.array([0, 0, 0]) line_point2 = np.array([0, 1, 0]) angle = 90 rotated_point = rotate_point(point, line_point1, line_point2, angle) print(rotated_point)This will rotate the point (1, 0, 0) 90 degrees around the line defined by (0, 0, 0) and (0, 1, 0). The output will be the 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.