Okay, here is an OpenSCAD script to create a parametric rocket model. You can adjust the variables at the beginning to change the rocket's shape, size, number of fins, etc.
/**
* Parametric Rocket Model
*
* Adjust the variables below to customize the rocket.
*/
// === Rocket Parameters ===
// --- Overall Size ---
body_height = 60; // Height of the main cylindrical body
body_radius = 8; // Radius of the main cylindrical body
// --- Nose Cone ---
nose_cone_height = 20; // Height of the nose cone
// nose_cone_radius = body_radius; // Nose cone radius matches body
// --- Engine Section ---
engine_height = 10; // Height of the engine section
engine_radius = 10; // Radius of the engine section (can be larger than body)
// --- Fins ---
num_fins = 4; // Number of fins (set to 0 for no fins)
fin_height = 15; // Height of the fins
fin_width_base = 12; // Width of the fin at the bottom (attaches to body)
fin_width_tip = 3; // Width of the fin at the top
fin_thickness = 2; // Thickness of the fins
fin_offset_z = 5; // Distance from the bottom of the body to the bottom of the fins
// --- Detail ---
$fn = 64; // Number of facets for curved surfaces (increase for smoother curves)
// === Modules for Components ===
/**
* Creates the main cylindrical body of the rocket.
*/
module rocket_body() {
// Cylinder is centered at Z=height/2 by default, but bottom is at Z=0
cylinder(h = body_height, r = body_radius);
}
/**
* Creates the nose cone at the top of the body.
*/
module rocket_nose_cone() {
// Position on top of the body
translate([0, 0, body_height]) {
// Cone with r1 at base (body radius) and r2=0 at tip
cone(h = nose_cone_height, r1 = body_radius, r2 = 0);
}
}
/**
* Creates the engine section at the bottom of the body.
*/
module rocket_engine_section() {
// Position below the body
translate([0, 0, -engine_height]) {
// Cylinder for the engine section
cylinder(h = engine_height, r = engine_radius);
}
}
/**
* Creates a single fin.
* The fin is created in the XZ plane with the attachment edge along the Z axis.
* It's extruded along the Y axis for thickness.
*/
module rocket_fin() {
// Check if dimensions are valid for a fin
if (fin_height > 0 && (fin_width_base > 0 || fin_width_tip > 0) && fin_thickness > 0) {
// Define the 2D shape of the fin in the XZ plane
// Points: [0,0] (bottom root), [0, fin_height] (top root),
// [fin_width_tip, fin_height] (top tip), [fin_width_base, 0] (bottom tip)
polygon_points = [
[0, 0],
[0, fin_height],
[fin_width_tip, fin_height],
[fin_width_base, 0]
];
// Extrude the 2D shape along the Y axis for thickness
linear_extrude(height = fin_thickness, center = true) // center=true extrudes equally in +Y and -Y
polygon(points = polygon_points);
} else {
// echo("Fin dimensions are zero or negative. Skipping fin.");
}
}
/**
* Creates multiple fins rotated around the body.
*/
module rocket_fins() {
if (num_fins > 0) {
// Calculate the angle between each fin
angle_step = 360 / num_fins;
// Loop to create and position each fin
for (i = [0 : num_fins - 1]) {
// Rotate the coordinate system for each fin
rotate([0, 0, i * angle_step]) {
// Translate the fin outwards by the body radius
// and up by the fin offset.
// The fin is defined with its attachment edge at [0,0,0] along Z.
// After rotation, [body_radius, 0, fin_offset_z] moves it correctly.
translate([body_radius, 0, fin_offset_z]) {
rocket_fin();
}
}
}
} // else no fins are generated
}
// === Main Rocket Assembly ===
module rocket() {
color("silver") // Body color
rocket_body();
color("red") // Nose cone color
rocket_nose_cone();
color("gray") // Engine color
rocket_engine_section();
color("orange") // Fin color
rocket_fins();
// Example: Add a window (optional)
// translate([body_radius * 0.8, 0, body_height / 2])
// rotate([0, 90, 0])
// cylinder(h = fin_thickness * 2, r = body_radius / 4, $fn = 16);
}
// === Render the Rocket ===
rocket();
How to use the script:
- Save: Save the code in a plain text file named
rocket.scad.
- Open: Open the file in OpenSCAD.
- Customize: Modify the variables at the top of the script (
body_height, body_radius, num_fins, etc.) to change the rocket's appearance.
- Preview: Press
F5 to quickly preview the model.
- Render: Press
F6 to fully render the model (necessary before exporting).
- Export: Use
File -> Export -> Export as STL... to save the model for 3D printing or other uses.
Explanation of the Code:
- Parameters: The variables at the top control the key dimensions of the rocket parts.
$fn: Controls the smoothness of curved surfaces. A higher number results in a smoother surface but increases rendering time and file size.
- Modules: The script is broken down into modules (
rocket_body, rocket_nose_cone, etc.). This makes the code organized and reusable.
translate(): Moves an object in 3D space [x, y, z].
rotate(): Rotates an object around an axis [rx, ry, rz].
cylinder(): Creates a cylinder. h is height, r is radius (or r1, r2 for cones).
cone(): Creates a cone. h is height, r1 is bottom radius, r2 is top radius.
polygon(): Creates a 2D shape from a list of points [[x1,y1], [x2,y2], ...].
linear_extrude(): Turns a 2D shape into a 3D shape by extruding it along an axis (by default, the Z axis). height is the extrusion distance. center=true extrudes the shape equally in positive and negative directions along the extrusion axis.
for loop: Used in rocket_fins to create multiple fins by rotating a single fin instance around the Z axis.
color(): Adds color to a module (mostly for visualization within OpenSCAD).
rocket(): A main module that calls all the component modules to assemble the complete rocket.
rocket();: This line at the very end actually tells OpenSCAD to render the rocket module.
Feel free to add more parameters or modules for additional features like windows, payload sections, staging lines, etc.!