The library geometry-blender is designed to smoothly blend geometric objects using the following operations
- Union
- Intersection
- Subtraction
- Global Deformations
Solid objects in 3-dimensional are represented using
smooth mathematical functions f = f(x,y,z)
, so that a point (x,y,z)
belongs to
the object if and only if it satisfies the inequality
f(x,y,z) >= 1/2
The border of such an object is a surface that consists of set
of points (x,y,z)
that satisfy the equality
f(x,y,z) == 1/2
We can mesh this level set using algorithms like Marching Cubes or Marching Tetrahedra, and then render into the screen by using a graphing system (like plotly).
(See Jupyter notebook DoubleTorus.ipynb )
We can create a double torus as follows. First, we join two lenticular shaped objects using the code
b1 = Ball3D()
b1.scale(1/2,1/2,1/3)
b1.translate(-1/2,0,0)
b2 = Ball3D()
b2.scale(1/2,1/2,1/3)
b2.translate(1/2,0,0)
obj1 = b1 + b2
-
The ball
b1
represent a ball radius1
centered at the origin. We scaleb1
by a factor1/2
along thex
andy
plane and by a factor of1/3
along thez
axis; This produces a lenticular shaped object which is thinner in thez
-direction. Next, we translateb1
by an amount of-1/2
in thex
-direction. -
The object
b2
is constructed in a similar way, but is translated by an amount of1/2
in thex
-direction. -
Finally, we construct
obj1
as the blended sum (union) ofb1
andb2
(see Figure below)
We now construct a new object obj2
by making two holes to obj1
. We
do this by subtracting two cylinders c1
and c2
from obj1
.
c1 = Cylinder3D()
c1.scale(1/8,1/8,1)
c1.translate(-1/2,0,0)
c2 = Cylinder3D()
c2.scale(1/8,1/8,1)
c2.translate(1/2,0,0)
obj2 = obj1-(c1+c2)
We can twist one of the of handles of the double torus as follows
theta = pi/2
b2r = b2.rotated(1,0,0,theta)
c2r = c2.rotated(1,0,0,theta)
obj3 = (b1+b2r)-(c1+c2r)
The above code constructs b2r
and c2r
by rotating b2
and c2
an angle of pi/2
;
using the vector (1,0,0)
as the axis of rotation. The resulting object obj3
is shown in
the figure below.
To avoid package conflicts it is recommended to create a Python Virtual Environment for installation. This can be done at a terminal a follows
- Anaconda :
conda create --name geometry python=3
We then need to activate this environment as follows:
- Anaconda :
conda activate geometry
The packages numpy, sympy and scikit-image need to be present in the virtual environment. This can be achieved by typing (at a terminal)
- Anaconda :
conda install numpy sympy scikit-image
Clone the repository by typing
git clone https://github.com/valerocar/geometry-blender.git
,
To be able to execute the Jupyter Notebooks in demos you will need to install the plotly graphing library as follows:
- Anaconda Python: conda install -c plotly plotly