Giter Site home page Giter Site logo

valerocar / geometry-blender Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 0.0 29.49 MB

Building geometric objects using blending techniques and global deformations

License: MIT License

Python 100.00%
level-sets implicit-functions geometry 3d-graphics 3d-models marching-cubes differential-geometry computer-graphics metaballs torus

geometry-blender's Introduction

Geometry Blender

Double Torus

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).


Example: Double Torus in 3-dimensional space

(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 radius 1 centered at the origin. We scale b1 by a factor 1/2 along the x and y plane and by a factor of 1/3 along the z axis; This produces a lenticular shaped object which is thinner in the z-direction. Next, we translate b1 by an amount of -1/2 in the x-direction.

  • The object b2 is constructed in a similar way, but is translated by an amount of 1/2 in the x-direction.

  • Finally, we construct obj1 as the blended sum (union) of b1 and b2 (see Figure below)

Double Torus

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)

Double Torus

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.

Double Torus

Requirements and installation

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

![Animation]

geometry-blender's People

Contributors

valerocar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.