On this page:
3.10.1 Exercises 18
3.10.1.1 Question 53
3.10.1.2 Question 54

3.10 Cylindrical Coordinates

We have seen in previous sections some examples of the use of rectangular and polar coordinate systems. It also became clear that a thoughtful choice of the coordinate system can greatly simplify a geometric problem.

For three-dimensional modeling, besides the rectangular and polar coordinate systems, it is also common to use two other coordinate systems: cylindrical coordinates and spherical coordinates.

As we can see in this figure, a point in cylindrical coordinates is defined by a radius \(\rho\) that defines the distance to the \(Z\) axis, an angle \(\phi\) with the \(X\) axis and a height \(z\). It is easy to see that the radius and the angle match the polar coordinates of a point’s projection on the \(XY\) plane.

Cylindrical coordinates.

image

From the figure above, we can easily see that a point in cylindrical coordinates \((\rho, \phi, z)\) is denoted in rectangular coordinates as \[(\rho \cos \phi, \rho \sin \phi, z)\]

Likewise, a point in rectangular coordinates \((x,y,z)\) is represented in cylindrical coordinates as \[(\sqrt{x^2+y^2},\arctan\frac{y}{x}, z)\]

These equivalences are assured by the constructor of cylindrical coordinates cyl. Although this function is predefined in Khepri, it is not difficult to imagine its definition:

cyl(rho, phi, z) = xyz(rho*cos(phi), rho*sin(phi), z)

A similar definition is available for the function vcyl, which creates vectors in cylindrical coordinates.

3.10.1 Exercises 18
3.10.1.1 Question 53

Define the selectors cyl_rho, cyl_phi and cyl_z which return, respectively, the components \(\rho\), \(\phi\) and \(z\) of a point built with the constructor cyl.

3.10.1.2 Question 54

Define a function stairs capable of building a spiral staircase. The following image shows three different examples of spiral staircases:

image

It can be seen that each staircase is formed by a central cylinder, onto which \(10\) cylindrical steps are connected. Consider that the central cylinder has a radius of \(r\). Each step radius is equal to the one of the central cylinder, and the step’s width is \(10\) times the radius. Each is distanced \(h\) from the previous one and, seen from a top view, makes with it an angle \(\alpha\).

The function stairs should have as parameters the coordinates of the central cylinder’s base, the radius \(r\), the height \(h\) and the angle \(\alpha\). As an example, consider the stairs in the previous figure, which were created by the following expressions:

stairs(xyz(0, 0, 0), 1.0, 3, pi/6)

stairs(xyz(0, 40, 0), 1.5, 5, pi/9)

stairs(xyz(0, 80, 0), 0.5, 6, pi/8)