Difficulty:: Easy.
Next Tutorial: The Random Forest
Scaling an Object allows to make it bigger or deforma its proportions. In this tutorial we will show how to deform a Cylinder (circular base) in order to get a Cylinder with elliptical base.
The following code:
Component myCylinder = Cylinder(10,40);
Declares a variable myCylinder, representing a cylinder of radius 20, and height 40. The Cylinder is centered on the xyz origin.
If we want to generate the OpenSCAD code for this cylinder, we simply run:
IndentWriter writer; writer << myCylinder; std::cout << writer;
This will send to the standard output the following
cylinder(h=40, r1=20, r2=20, $fn=100,center=true);
If we want to scale the cylinder in order to make its base face an ellipse with axis 30,20 and the same height
myCylinder.scale(30/20, 10/20, 1); writer << myCylinder; std::cout << writer;
If instead we want to make a scaled copy and leave the original cylinder unchanged we should write:
Component ellipticalCylinder = myCylinder.scaledCopy(30/20, 10/20, 1); writer << ellipticalCylinder; std::cout << writer;
The three parameters are respectively the scaling of the x, y, and z axis.
which will generate:
scale([45,0,0]){
cylinder(h=40, r1=20, r2=20, $fn=100,center=true);
}
The full code is:
int main() { // Cylinder of radius 1 and height 1 Component myCylinder = Cylinder(1,1); // Scale the cylinder to get an elliptical base of 20x10 and height 30 Component ellipCyl = myCylinder.scaledCopy(20,10,20); //generate the OpenScad code IndentWriter writer; writer << ellyCyl; cout << writer; return 0; }
Next Tutorial: The Random Forest