This repository includes multiple solutions for generating and analyzing 3D clothoid curves (spirals) using both SolidWorks VBA macros and Python scripts. The primary focus is on integrating SolidWorks for CAD modeling, Excel for data analysis, and Python for curve visualization and curvature computation.
- Generates a 3D clothoid curve using parametric equations x(t)=cos(t²) and y(t)=sin(t²)
- The z-coordinate is fixed at 0, but can be adjusted if needed
- Automatically creates a 3D sketch in SolidWorks with points calculated at discrete intervals
- Allows for custom start and end points in 3D space (startX, startY, startZ, endX, endY, endZ)
- Linear interpolation between points combined with sine wave functions
- Dynamic curve shape modification in 3D space
Parameters:
numPoints
: Number of points for the curve (default: 100)deltaT
: Step size for the parametric valuesstartX, startY, startZ
: Starting point coordinatesendX, endY, endZ
: Ending point coordinates
Note: Results are automatically converted to SolidWorks' default unit system (meters)
- Generates 2D plot of the clothoid curve in the XY-plane
- Integrates parametric equations numerically using
numpy.cumsum()
- Plots curvature κ(t) as 2t
- Displays curve and curvature function in separate subplots
- Includes all functionality of the first script
- Saves generated data (t, x, y, and curvature values) to Excel
- Uses pandas DataFrame for data management
- Creates
curve_and_curvature.xlsx
for analysis
Parameters:
t
: Parameter range (0 to 2 or 1)x(t)
: cos(t²) for x-coordinatey(t)
: sin(t²) for y-coordinatekappa(t)
: Curvature function (2t)
- Data export to Excel file with columns for t, x, y, and kappa
- Facilitates curve analysis using spreadsheet tools
- Compatible with both SolidWorks and Python workflows
- SolidWorks (any recent version)
- Python 3.x
- Required Python packages:
pip install numpy matplotlib pandas
- Open a part document in SolidWorks
- Access the VBA editor (Tools > Macro > New)
- Copy and paste the macro code
- Run the macro to generate the 3D clothoid curve
-
First Script (Visualization):
python clothoid.py
-
Second Script (Excel Export):
python excelclothoid.py
- SolidWorks macros require an active part document
- Python scripts provide independent visualization and analysis
- Excel integration enables data portability between tools
Feel free to submit issues and enhancement requests!