Basic "Shapes" Library complex

Library name: shapes

Functions to create and label basic shapes by using preexisting ASCIIsvg macro.  Version January 2022


By default, an image description is generated for each shape.

To import the library, include loadlibrary("shapes") in the question's common control.

The functions in this library can be used to draw and label basic shapes:

List of functions:

 

 Function output:

These functions output images that are defined in code by $gr = function("arguments") and then placed into a problem's text with $gr.

 

 Functions:

draw_angle

Draws and labels an angle.

Syntax: draw_angle("measurement,[label],[noarc]",["rotate,[ang]"],["axes"])

The first option must include the angle measurement.

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_angle("340,theta","axes") -- Draws a 340 degree angle, labeled θ, in standard position on coordinate axes, and an angle arc with arrow is shown.

$gr = draw_angle("120,2pi/3,noarc") -- This draws a 120 degree angle in standard position, labeled 2π/3. Angle arc is not drawn.

$gr = draw_angle("-150,-150","axes","rotate") -- This draws a 150 degree angle clockwise, labeled -150°. Coordinate axes are drawn, and starting ray of the angle is rotated by a random angle. Angle arc is shown with arrow.

draw_circle

Draws and labels a circle.

Syntax: draw_circle(["option 1", "option 2", ...])

draw_circle() -- this draws a circle with no labels.

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_circle("diameter,7 feet") -- This is a circle with a diameter labeled with "7 feet".

$gr = draw_circle("center,P", "angle,45,pi/4") -- This circle has a center labeled P and a 45 degree angle drawn with the label π/4.

$gr = draw_circle("radius", "point,0,M", "point,90") -- This is a circle with a horizontal radius (unlabeled) drawn from the center to labeled point M. Also, point at 90 degrees is drawn but not labeled.

draw_circlesector

Draws and labels a scaled sector of a circle.

Syntax: draw_circlesector("angle,measurement,[label]", ["option 1", "option 2", ...])

draw_circlesector("angle,measurement,[label]") -- this draws a circle sector with angle measurement (given in degrees), and optional label.

Note: Up to two "angle" arguments may be used. Test to make sure labels do not overlap (for close angles).

Using "angle,measurement" is required for draw_circlesector.

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_circlesector("angle,45,pi/4") -- This is a 45 degree sector with angle labeled π/4.

$gr = draw_circlesector("angle,45", "point,45,(3;3)", "axes") -- This is a 45 degree sector with point on circle at 45 degrees labeled (3,3). The x and y axes are shown.

draw_cone

Draws and labels a right, circular cone.

Syntax: draw_cone([diameter,height],[option 1],[option 2],[option 3]

draw_cone() -- draws a random cone with no labels. The point of the cone is at the top.

draw_cone(a,b) -- makes a scaled drawing of a cone with diameter 'a' and height 'b'.

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_cone(1,1,"radius,r=12") -- A cone with equal diameter and height, with radius drawn and labeled 'r=12'.

$gr = draw_cone("height,x","fill,30","invert") -- A random cone, inverted, with its height labeled 'x' and filled up to 30 percent of its height.

draw_cylinder

Draws and labels a circular cylinder.

Syntax: draw_cylinder([diameter,height],[option 1],[option 2],[option 3]

draw_cylinder() -- draws a random cylinder with no labels.

draw_cylinder(a,b) -- makes a scaled drawing of a cylinder with diameter 'a' and height 'b'.

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_cylinder(1,1,"radius,r=12") -- A cylinder with equal diameter and height, with radius drawn and labeled 'r=12'.

$gr = draw_cylinder("height,x","fill,30") -- A random cylinder with height labeled 'x' and filled 30 percent.

draw_rectangle

Draws a scaled rectangle with labels.

Syntax: draw_rectangle(["option 1", "option 2", ...])

draw_rectangle() -- this draws a random rectangle with no labels

Each option is a list inside quotes. Options include:

Notes:

  1. "base" and "height" must be used together as they define the size of the rectangle.

Examples:

$gr = draw_rectangle("base,1,x","height,2,y","points,(0;0),(5;0)") -- A rectangle with 1:2 ratio of base-to-height, bottom horizontal side labeled "x", right-hand vertical side labeled "y", and bottom two vertices labeled (0,0) and (5,0).

draw_rectprism

Draws and labels a rectangular prism.

Syntax: draw_rectprism([length,depth,height],[option 1],[option 2],[option 3]

draw_rectprism() -- draws a random rectangular prism with no labels.

draw_rectprism(length,depth,height) -- draws a scaled rectangular prism with no labels.

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_rectprism(4,5,6,"labels,a,,c","fill,30") -- A rectangular prism that is 4 units long, 5 units deep and 6 units tall, with front length edge labeled 'a' and height edge labeled 'c'. Prism is filled up to 40 percent of its height.

draw_sphere

Draws and labels a sphere.

Syntax: draw_sphere([option 1],[option 2],[option 3]

draw_sphere() -- draws a sphere with no labels.

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_sphere("radius,r=12","fill,50") -- A sphere with radius drawn and labeled 'r=12', filled half way up from the bottom.

draw_square

Draws and labels a square.

Syntax: draw_square(["option 1", "option 2", ...])

draw_square() -- this draws an unlabeled square

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_square("base,x","points,(0;0),(5;0)") -- A square with bottom horizontal side labeled "x", and bottom two vertices labeled (0,0) and (5,0).

draw_triangle

Draws a scaled triangle, where size can be defined by its "angles", "sides" or "random".

Syntax: draw_triangle(["option 1", "option 2", ...])

draw_triangle() -- this draws a random triangle with no labels.

Each option is a list inside quotes. Options include:

Notes

  1. If "angles" is given after "sides", then A,B,C are omitted (since the "sides,a,b,c" will define the triangle).
  2. If "sides" is used after "angles", then a,b,c are omitted (since the "angles,A,B,C" will define the triangle).
  3. If "angles" is used to define triangle, then angles should be given in degrees, and the degree symbol will displayed by default. To not display the degree symbol, use "rad" in the label. E.g. "angles,50,60,70,A rad,B rad,C rad"
  4. If neither "angles" nor "sides" are used, then defaults to "random".
  5. The right angle box symbol is always displayed, unless an angle arc is also used on the right angle.
  6. Common Greek letters (pi, alpha, beta, gamma, theta, phi, tau) will be displayed as their html symbols. E.g. you can type a label as "3 pi/4" or "alpha". Using a Greek letter will suppress the degree symbol.
  7. If a label is a point, type it as (x;y).
  8. For "sides,a,b,c" and "angles,A,B,C", the number "a" is the side opposite angle "A", etc.
  9. By default, triangles are drawn with vertex 0 at bottom left, vertex 1 at bottom right, and vertex 2 at top. Use "rotate" to rotate the triangle.

Examples:

$gr = draw_triangle("angles,30,60,90,pi/6,pi/3") -- A 30-60-90 right triangle with angle labels π/6 and π/3. The right angle box is displayed by default.

$gr = draw_triangle("sides,5,10,12,a,b,c", "angles,A,B,C") -- A triangle with side lengths 5, 10 and 12, labeled with letters a,b,c. Angles are labeled with A,B,C.

$gr = draw_triangle("rotate","points") -- A random triangle with points on the vertices (unlabeled), drawn with random rotation.

$gr = draw_triangle("angles,30,90,60","rotate,90") -- A 30-60-90 triangle rotated so the right edge is drawn vertically and the right angle is at top right.

$gr = draw_triangle("random","points,P,Q,R","angles,a,b,c,(,((,(((") -- A triangle with random angles, points are labeled P,Q,R, angles are labeled a,b,c and they have arcs (, (( and (((.

$gr = draw_triangle("points,A,B,C","angles,30,110,40","altitude,1,0,0,P") -- A 30-110-40 triangle (unlabeled angles) with vertices labeled A,B,C, and an altitude drawn down from point A, labeled with the letter "P".

draw_polygon

Draws and labels a polygon with n sides.

Points drawn counterclockwise. By default, first side is horizontal on the bottom.

Syntax: draw_polygon([n],["option 1", "option 2", ...])

draw_polygon() -- this draws a random polygon with between 3 and 9 sides.

draw_polygon(n) -- this draws an n-sided polygon. Maximum number of sides is 50.

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_polygon(5,"axes","norotate","regular","points,P") -- A regular pentagon with points on vertices, and first vertex on positive x-axis labeled "P".

draw_prismcubes

Draws a rectangular prism sliced into cubes.

Syntax: draw_prismcubes([option 1],[option 2],[option 3]

draw_prismcubes() -- this draws a cube with no labels.

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_prismcubes("cubes,2,5,3","labels,a,b,c") -- A 2x5x3 rectangular prism of cubes, dimensions labeled a, b and c.

$gr = draw_prismcubes("labels,L,H,W") -- A 1x1x1 cube, dimensions labeled L, H and W.

draw_pyramid

Draws and labels a pyramid with rectangular base.

Syntax: draw_pyramid([length,width,height],[option 1],[option 2],[option 3]

draw_pyramid() -- draws a random pyramid with no labels.

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_pyramid(4,5,6,"length,4","width,5","height,6","fill,30","invert") -- A pyramid with tip at bottom and rectangular base at top, filled with colored material up to 30 percent of its height, with the rear edge of the base labeled 4, the left edge of the base labeled 5 and its height drawn and labeled 6.

draw_polyomino

Draws and labels a random, connected polyomino.

Syntax: draw_polyomino([n],[option 1],[option 2],[option 3])

draw_polyomino() -- draws a random polyomino with between 3 and 9 squares.

draw_polyomino(n) -- draws a random polyomino with at least n squares.

Each option is a list inside quotes. Options include:


Examples:

$gr = draw_polyomino(5,"fill,transblue","grid") -- A random polyomino with 5 squares (i.e. a "pentomino"), shaded transparent blue, and shown on a grid.

$gr,$a,$p = draw_polyomino("fill","data") -- $gr is a random polyomino with between 3 and 9 squares, shaded with a random color; $a is the number of squares in the shape; $p is the perimeter of the shape

Back to top of page