Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Off-axis rotation producing unexpected results

$
0
0

I’d appreciate any assistance with the following issue:

Goal
As can be observed by running the following script, my goal is to have the upper surface(A) rotated, with center of rotation at the center of its lower edge(B) and axis of rotation aligned to the normal of the plane upon which that edge sits(C).

Expected Results
Surface (A) should rotate maintaining contact at all points along their common edge.

Actual Results
They lose contact once rotation occurs.

Python script

import rhinoscriptsyntax as rs
import math

# Create a cylinder at the origin with radius 5 and height 10
cylinder = rs.AddCylinder([0,0,0], 10, 5)

# Define the start and end points for the cutting plane
point0 = [0, 0, 5]
point1 = [1, 0, 5]

# Define the normal for the cutting plane
normal = [0, 1, math.cos(math.radians(90-15))]

# Create the cutting plane using AddCutPlane
tilted_plane = rs.AddCutPlane([cylinder], point0, point1, normal)

# Cut the cylinder using the tilted plane
cut_cylinder = rs.SplitBrep(cylinder, tilted_plane)

# Delete the original cylinder and tilted plane to leave only the cut pieces
rs.DeleteObject(cylinder)
rs.DeleteObject(tilted_plane)

# Rotate the upper surface
# The upper surface is the second object in the cut_cylinder list
upper_surface = cut_cylinder[1]

# Calculate the true normal to the cut plane using the cross product
vec1 = [point1[i] - point0[i] for i in range(3)]
true_normal = rs.VectorCrossProduct(vec1, normal)

# Define the center of rotation as the center of the tilted circle (interface between the two surfaces)
center_of_rotation = [0, 0, 5]  # This should be the center of the tilted circle

# Rotate the upper surface by 90 degrees
rs.RotateObject(upper_surface, center_of_rotation, 90, axis=true_normal)

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles