
Lesson 10 - Extrusions
In this lesson we learn about extrusions. Extrusions are similar to forcing plasticine or plastic through a mold.
A basic shape is defined and any 'holes' within it, then the shape is 'extruded' along a path.
Timings
Teaching: 40 min
Exercises: 20 min
Objectives
By the end of the lesson the student should be able to:
Understand how to create an extruded shape.
Add a variety of shapes to the extrusion and position them.
Extrude a shape in a particular 'path' to produce a variety of objects.
Position the final extrusion in the scene.
The program
The code below creates an extruded shape from a rectangle with predefined 'hole' shapes.
#define start end end points for Extrusion which is centered around 0 in the z plane
E1start=vec(0,0,0.7)
E1end=vec(0,0,-0.7)
main_shape=shapes.rectangle(width=10, height=6) #defines the principle shape - (a rectangle)
#define shapes that will represent 'holes' in the main shape
#if these shapes cut the border of the main shape or overlap each other an error will occur.
hexagon=shapes.hexagon(pos=[-2,1], length=1.2)
triangle=shapes.triangle(pos=[0,-1.6], length=1.2)
trapezoid=shapes.trapezoid(pos=[3,0.6], width=1.6, height=1, top=0.6 )
circle=shapes.circle(pos=[-2,-1.6],radius=1)
# Genereate the extrusion
E1 = extrusion(path=[E1start, E1end], texture=textures.wood_old,
shape=[ main_shape,
hexagon,
triangle,
trapezoid,
circle]
)
E1.pos= vector(0,0,-3) #give the extrusion a position in 3D space
Things to note
In the above example we specify the start and end positions of the extrusion. Note that we are extruding along the 'z' axis.
Next we specify that the main shape should be a rectangle and we create a series of other 2-D shapes which leave the 'holes' in the main object.
We perform the extrusion by giving it the previously defined shapes. Note that the first shape in the 'shape[]' list is the shape the others are extruded into.
Lastly the extrusion is given its final position. Here it is moved back 3 units in the -z-direction.
If shapes overlap or fall outside of the main shape, VPython will issue an error screen with an outline of where the problem shape is occurring.
The program will run when all the shapes lie within the main shape and none of them intersect!
Exercise 1
Copy the program above and do the following:
1. Create a pentagon in the 'wood' and place it below the trapezoid.
2. Increase the depth of the extrusion by 1 unit along the z axis.
If you go wrong, you will see the error screen mentioned above. Return to the editor and try new values.
#define start end end points for Extrusion which is centered around 0 in the z planeSolution to Exercise 1
E1start=vec(0,0,0.7)
E1end=vec(0,0,-0.7)
main_shape=shapes.rectangle(width=10, height=6) #defines the principle shape - (a rectangle)
#define shapes that will represent 'holes' in the main shape
hexagon=shapes.hexagon(pos=[-2,1], length=1.2)
triangle=shapes.triangle(pos=[0,-1.6], length=1.2)
trapezoid=shapes.trapezoid(pos=[3,0.6], width=1.6, height=1, top=0.6 )
pentagon = shapes.pentagon(pos=[3,-1.6],length=1) #solution
circle=shapes.circle(pos=[-2,-1.6],radius=1)
# Genereate the extrusion
E1 = extrusion(path=[E1start, E1end], texture=textures.wood_old,
shape=[ main_shape,
hexagon,
triangle,
trapezoid,
pentagon, #solution
circle])
E1.pos= vector(0,0,-4) #give the extrusion a position in 3D space
Extrusions in a curve
copper = vec(0.722,0.451,0.200) # defines a coppery colour
#Generate the extrusion, noting that the first shape in the list forms the main body of the extrusion
E2 = extrusion(path=paths.arc(radius=1.7, angle2=pi), texture=textures.metal,
shape=[ [
shapes.triangle(length=2),
shapes.circle(pos=[0,.5], radius=0.2),
shapes.trapezoid(pos=[0,-0.2], width=0.6, height=0.4)
] ],
start_face_color=copper, end_face_color=copper) # set the colour for the open faces of the extrusion
E2.pos=vector(0,0,0)# set extrusion position
Things to note
.
All of the following shapes have path versions: paths.rectangle(),
paths.circle(), paths.ellipse(),
paths.arc(), paths.line(),
paths.triangle(), paths.pentagon(),
paths.hexagon(), paths.octagon(),
paths.ngon(), paths.star(),
and paths.cross().
In the example we use paths.arc(radius=1.7, angle2=pi) to give a rounded shape to the extrusion, but we could use any of the above.
Exercise 2
Copy the program above and do the following:
1. Modify the program to make an extrusion by using star(n=10), which creates a ten-sided star shape.
Note: A star is a closed shape unlike an arc, so the start-face and end-face attributes are not required.
copper = vec(0.722,0.451,0.200)# defines a coppery colourSolution to Exercise 2
E2 = extrusion(path=paths.star(n=10), texture=textures.metal,
shape=[ [
shapes.cross(width=2, thickness=0.2),
shapes.circle(pos=[0,.5], radius=0.2),
shapes.trapezoid(pos=[0,-0.2], width=0.6, height=0.4)
] ],
) # Note: you will not see the circle or trapezoid shapes as the star path is 'closed' and are ignored.
E2.pos=vector(0,0,0)
Conclusion
You should now be able to:
Understand how to create an extruded shape.
Add a variety of shapes to the extrusion and position them.
Extrude a shape in a particular 'path' to produce a variety of objects.
Position the final extrusion in the scene.