Writing Functions for Geometric Shapes

Here we'll practice writing functions by creating functions that calculate things like the surface-areas and volumes of different 2d and 3d shapes.
What is the volume and surface area of a sphere?
Notes and Code Outcome

Sphere

Write a function that calculates the surface area (A) of a sphere of radius (r). $$ A = 4 \pi r^2 $$
Show Notes ▼

Sphere

Test the function by finding the surface area of a sphere with radius 5.
Code
Show Notes ▼
Results.
Show Notes ▼

Sphere function test (multiple values)

Use your sphere function to find the surface areas of spheres with radii: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
Code.
Show Notes ▼
Results.
Show Notes ▼

Sphere: Volume

Write a function that calculates the volume (V) of a sphere of radius (r). $$ V = \frac{4}{3} \pi r^3 $$

Cylinder

Write functions to find the surface area and volumes of cylinders.

Rectangular Prisms

Write functions to find the surface area and volumes of rectangular prisms.

Triangles

Challenge:
  • Write a function to find the area of a triangle given three points.
  • Write a function that draws a triangle (using Glowscript) given three points.