On this page:
7.4.1 Exercises 35
7.4.1.1 Question 135
7.4.1.2 Question 136
7.4.1.3 Question 137

7.4 Slice of Regions

Besides the union, intersection and subtraction operations, Khepri provides the section operation, implemented by the function slice. This operation allows the modification of a region through its sectioning by a plane. The specification of the plane is done through a point contained in that plane and a normal vector to the plane. In this case, the vector’s direction indicates which region we intend to discard. This figure illustrates the slicing of a cube by a (virtual) plane defined by a point \(P\) and by a vector \(\vec{n}\). This operation’s syntax is slice(region, P, n).

Sectioning of a solid by a slicing plan defined by a point \(P\) belonging to the plane and by a vector \(\vec{n}\) normal to the plane.

image

As an example of using this operation, consider the creation of a wedge (with an opening angle of \(\phi\)) of a sphere with a radius \(r\) and centered at a point \(P\). The wedge is obtained through two vertical slices on the sphere.

wedge_sphere(p, r, phi) =

  slice(slice(sphere(p, r), p, vcyl(1, 0, 0)), p, vcyl(1, phi, 0))

This figure presents wedges with different openings, generated by the function wedge_sphere.

Wedges of a sphere. From right to left, the angle between the slicing planes varies from \(0\) to \(\pi\) in increments of \(\pi/6\).

image

Frequently, the slicing planes we want to employ will have normals parallel to the coordinates’ axes. To ease these cases, we will assume the existence of the following functions:These functions are already predefined in Khepri.

u0() = xyz(0, 0, 0)

uvx() = vxyz(1, 0, 0)

uvy() = vxyz(0, 1, 0)

uvz() = vxyz(0, 0, 1)

Using these functions, we can easily create solids with complex shapes. For example, an eighth of a sphere is trivially obtained through three slices:

slice(slice(slice(sphere(u0(), 2),

                  u0(),

                  uvx()),

            u0(),

            uvy()),

      u0(),

      uvz())

As a final example, consider the modeling of a tetrahedron. A tetrahedron is a polyhedron with four triangular faces and is the simplest of the Platonic solids. These four faces unite four vertices that completely specify a tetrahedron. Although Khepri provides several operations to model some fundamental solids, such as the cuboid or the regular pyramid, it does not provide a specific operation to create tetrahedrons.

To implement the tetrahedron, we can slice a cuboid that inscribes the four vertices of the tetrahedron. To specify the enveloping cuboid, we need to calculate the maximum and minimum coordinate values of the tetrahedron’s vertices. Then, we need to slice the cuboid using the four planes matching the faces of the tetrahedron, which are defined by the combination of the four vertices taken three by three. Thus, assuming that the tetrahedron has the vertices \(P_0\), \(P_1\), \(P_2\), and \(P_3\), the first slice will be determined by the plane containing the points \(P_0\), \(P_1\), and \(P_2\), while preserving the part which contains \(P_3\), the second slice will be defined by the points \(P_1\), \(P_2\), and \(P_3\), while preserving \(P_0\), the third slice will be defined by the points \(P_2\), \(P_3\), and \(P_0\), while preserving \(P_1\), and the fourth slice by the points \(P_3\), \(P_0\), and \(P_1\), while preserving \(P_2\).

Each of these planes will be specified in the slicing operation by a point and the corresponding normal vector to the plane. To calculate this vector, we need to use the cross product of two vectors (implemented by the predefined cross function) and we have to verify if the normal is pointing towards the opposite direction of the point to preserve, which we can do by verifying the sign of the dot product (implemented by the predefined dot function) between the normal vector and the vector that ends at the point to preserve.

normal_points(p0, p1, p2, p3) =

  let v0 = p1-p0,

      v1 = p2-p0,

      n = cross(v0, v1)

    dot(n, p3-p0) < 0 ? n : n*-1

  end

tetrahedron(p0, p1, p2, p3) =

  let pmin = xyz(min(p0.x, p1.x, p2.x, p3.x),

                 min(p0.y, p1.y, p2.y, p3.y),

                 min(p0.z, p1.z, p2.z, p3.z)),

      pmax = xyz(max(p0.x, p1.x, p2.x, p3.x),

                 max(p0.y, p1.y, p2.y, p3.y),

                 max(p0.z, p1.z, p2.z, p3.z)),

      solid = box(pmin, pmax)

    solid = slice(solid, p0, normal_points(p0, p1, p2, p3))

    solid = slice(solid, p1, normal_points(p1, p2, p3, p0))

    solid = slice(solid, p2, normal_points(p2, p3, p0, p1))

    solid = slice(solid, p3, normal_points(p3, p0, p1, p2))

    solid

  end

This figure presents the several phases of the slicing process of the cuboid until the tetrahedron is obtained.

The creation of a tetrahedron by successive slices in an enveloping cuboid.

image

7.4.1 Exercises 35
7.4.1.1 Question 135

In 1609, Johannes Kepler Johannes Kepler was a famous mathematician and astronomer who, among many other contributions, established the laws of planetary motion. baptized the polyhedron illustrated in the following image as stella octangula. This eight-pointed star, also known as stellated octahedron is, in fact, a composition of two tetrahedrons.

image

Define the function stellated_octahedron which, given the center of the cube enveloping the octahedron and the length of the side of that cube, produces the stellated octahedron.

7.4.1.2 Question 136

The following image represents successive iterations of the Sierpiński tetrahedron, Wacław Sierpiński was a Polish mathematician who made considerable contributions to set theory and topology. Sierpiński described a bi-dimensional version of this pyramid in 1915. also called tetrix. The Sierpiński tetrahedron is a three-dimensional fractal that can be produced recursively through an imaginary tetrahedron with midpoints of each edge constituting the vertices of sub-Sierpiński tetrahedrons.

image

Define the sierpinski function which, from the coordinates of the four vertices and the desired level of recursion, creates the corresponding Sierpiński tetrahedron.

7.4.1.3 Question 137

Consider the spherical cap presented below, characterized by the two points \(P_0\) and \(P_1\), and by the diameter \(d\) of the cap’s base.

imageimage

Define the spherical_cap function that receives the points \(P_0\) and \(P_1\) and the diameter \(d\) of the cap’s base. Suggestion: determine the position and dimension of the sphere and use an appropriate slicing plan.