On this page:
3.3.1 Exercises 14
3.3.1.1 Question 40
3.3.1.2 Question 41
3.3.1.3 Question 42
3.3.1.4 Question 43

3.3 Bi-dimensional Drawing

In this section we will introduce some bi-dimensional drawing operations.

In order to visualize the shapes that we will create, we need to have a CAD application, like AutoCAD or Rhinoceros (commonly abbreviated to Rhino). The choice of which CAD application we wish to use is made by employing the backend function together with the argument autocad or rhino. Therefore, a program that uses Khepri usually starts with:

using Khepri

backend(autocad)

or with:

using Khepri

backend(rhino)

depending on the user’s preference for AutoCAD or Rhino, respectively.

Let us start by considering the creation of three circles. For that we can use the function circle, which receives the center point and the radius as arguments. In this figure you can see the result of the following program in AutoCAD:From here onwards, we will omit the header that requires Khepri and chooses the CAD application and, instead, we will focus our attention on the operations for geometric modeling.

circle(pol(0, 0), 4)

circle(pol(4, pi/4), 2)

circle(pol(6, pi/4), 1)

A series of circles.

image

Another frequently used operation is the one that creates line segments: line. In its simplest form, it takes the two positions of its endpoints as arguments. However, it is possible to invoke this function with any number of positions, which will be connected to form a polygonal line.

This figure shows the result produced by the following expression:

line(xy(-1, -1), xy(-1, 0), xy(1, 0), xy(1, 1))

A polygonal line.

image

In case we wish to draw closed polygonal lines, it is preferable that we use the polygon function, which is very similar to the function line but with the difference that it creates an additional segment connecting the last position with the first. This figure shows the result of the following expression:

polygon(pol(1, 2*pi*0),

        pol(1, 2*pi*1/5),

        pol(1, 2*pi*2/5),

        pol(1, 2*pi*3/5),

        pol(1, 2*pi*4/5))

For drawing regular polygons, i.e., polygons that have equal edges and angles, as the one shown in this figure, it is preferable to use the function regular_polygon. This function receives as arguments the number of sides, the center position, a radius, a rotation angle, and a boolean to indicate if the radius refers to an inscribed circle (i.e. the radius is the distance from the edges’ midpoints to the center) or a circumscribed circle (i.e. the radius is the distance from the vertices to the center). If omitted, the center point will be considered the origin, the radius will have one unit of measurement, the angle will be considered zero and the circle will be circumscribed.

Using the regular_polygon function, this figure can be obtained by:

regular_polygon(5)

A polygon.

image

More interesting examples can be obtained by different rotation angles. For example, the following expressions will produce the image shown in this figure:

regular_polygon(3, xy(0, 0), 1, 0, true)

regular_polygon(3, xy(0, 0), 1, pi/3, true)

regular_polygon(4, xy(3, 0), 1, 0, true)

regular_polygon(4, xy(3, 0), 1, pi/4, true)

regular_polygon(5, xy(6, 0), 1, 0, true)

regular_polygon(5, xy(6, 0), 1, pi/5, true)

Overlapping triangles, squares and pentagons with different rotation angles.

image

For four-sided polygons aligned with the \(X\) and \(Y\) axes, there is a very simple function: rectangle. This function can either be used with the position of its bottom left corner and top right corner or with the position of its bottom left corner and the rectangle dimensions, as exemplified below and represented in this figure:

rectangle(xy(0, 1), xy(3, 2))

rectangle(xy(3, 2), 1, 2)

A set of rectangles.

image

In the following sections we will introduce the remaining modeling functions available in Khepri.

3.3.1 Exercises 14
3.3.1.1 Question 40

Recreate the drawing presented in this figure but, this time, using rectangular coordinates.

3.3.1.2 Question 41

We wish to place two circles with unit radius around an origin so that the circles are tangent to each other as shown in the following drawing:

image

Write a sequence of expressions that produce the above image.

3.3.1.3 Question 42

We wish to place four circles with unit radius around an origin so that the circles are tangent to each other as shown in the following drawing:

image

Write a sequence of expressions that produce the above image.

3.3.1.4 Question 43

We wish to place three circles with unit radius around an origin so that the circles are tangent to each other as shown in the following drawing:

image

Write a sequence of expressions that produce the above image.