Created
October 14, 2025 10:34
-
-
Save stephensmitchell/4d4a355a9acb53d319ee0405e717f408 to your computer and use it in GitHub Desktop.
Creating a Cylinder Between Two Points
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #https://help.alibre.com/articles/#!alibre-help-v28/creating-a-cylinder-between-two-points | |
| # creates a cylinder between two arbitrary points | |
| from math import sqrt | |
| # ends of cylinder are centered on these points | |
| cyl_p1 = [1, 5, 2] | |
| cyl_p2 = [10, 14, 8] | |
| # diameter of cylinder | |
| diameter = 6 | |
| # get length of cynlinder using euclidean distance | |
| length = sqrt((cyl_p2[0] - cyl_p1[0])**2 + (cyl_p2[1] - cyl_p1[1])**2 + (cyl_p2[2] - cyl_p1[2])**2) | |
| # calculate normal vector for the plane at the first end of the cylinder | |
| normal_vector = [cyl_p2[0] - cyl_p1[0], cyl_p2[1] - cyl_p1[1], cyl_p2[2] - cyl_p1[2]] | |
| # create part | |
| P = Part('Cylinder') | |
| # create plane for one end of the cylinder | |
| cyl_plane = P.AddPlane('Cyl Start Plane', normal_vector, cyl_p1) | |
| P.AddAxis('Cylinder Axis', cyl_p1, cyl_p2) | |
| # draw a circle on the plane | |
| S = P.AddSketch('Cylinder End', cyl_plane) | |
| [cx, cy] = S.GlobaltoPoint(cyl_p1[0], cyl_p1[1], cyl_p1[2]) | |
| S.AddCircle(cx, cy, diameter, False) | |
| # extrude into a cylinder | |
| P.AddExtrudeBoss('Cylinder', S, length, False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment