All Projects → pboechat → pyobb

pboechat / pyobb

Licence: MIT License
OBB implementation in python (using numpy)

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to pyobb

venn7
A musical interface based on symmetric 7-set Venn diagrams
Stars: ✭ 29 (-53.97%)
Mutual labels:  computational-geometry
home
Community for parametric furniture designs.
Stars: ✭ 44 (-30.16%)
Mutual labels:  computational-geometry
gproshan
geometry processing and shape analysis framework
Stars: ✭ 48 (-23.81%)
Mutual labels:  computational-geometry
3D interactive graphics rendering engine
Develop a 3D interactive graphics rendering engine
Stars: ✭ 31 (-50.79%)
Mutual labels:  computational-geometry
polygon-splitter
A small (<10kb minified) javascript library for splitting polygons by a polyline.
Stars: ✭ 20 (-68.25%)
Mutual labels:  computational-geometry
MidcurveNN
Computation of Midcurve of Thin Polygons using Neural Networks
Stars: ✭ 19 (-69.84%)
Mutual labels:  computational-geometry
bentley-ottmann
simple Java implementation of Bentley-Ottmann sweep line algorithm for listing all intersections in a set of line segments
Stars: ✭ 16 (-74.6%)
Mutual labels:  computational-geometry
bitpit
Open source library for scientific HPC
Stars: ✭ 80 (+26.98%)
Mutual labels:  computational-geometry
SDLP
Seidel's LP Algorithm: Linear-Complexity Linear Programming for Small-Dimensional Variables
Stars: ✭ 36 (-42.86%)
Mutual labels:  computational-geometry
point-in-polygon-hao
A point in polygon library based on the paper "Optimal Reliable Point-in-Polygon Test and Differential Coding Boolean Operations on Polygons" by Hao
Stars: ✭ 83 (+31.75%)
Mutual labels:  computational-geometry
ELEMENTS
The C++ ELEMENTS library contains a suite of sub-libraries to support mathematical functions (elements), data representations (MATAR), and novel mesh classes (geometry and SWAGE) to support a very broad range of element types, numerical methods, and mesh connectivity data structures useful for computational physics and engineering.
Stars: ✭ 13 (-79.37%)
Mutual labels:  computational-geometry
tektosyne
The Tektosyne Library for Java provides algorithms for computational geometry and graph-based pathfinding, along with supporting mathematical utilities and specialized collections.
Stars: ✭ 52 (-17.46%)
Mutual labels:  computational-geometry
polytope
Geometric operations on polytopes of any dimension
Stars: ✭ 51 (-19.05%)
Mutual labels:  computational-geometry
rdp
A library providing FFI access to fast Ramer–Douglas–Peucker and Visvalingam-Whyatt line simplification algorithms
Stars: ✭ 20 (-68.25%)
Mutual labels:  computational-geometry
LimberGridView
LimberGridView, a powerful JavaScript Library using Computational Geometry to render movable, dynamically resizable, and auto-arranging grids. Written in vanilla JavaScript, it can be plugged into most frameworks, plus it has a plugin for React applications. It gives users the most optimal arrangements using its highly efficient and fine-tuned a…
Stars: ✭ 51 (-19.05%)
Mutual labels:  computational-geometry
topo
A Geometry library for Elixir that calculates spatial relationships between two geometries
Stars: ✭ 125 (+98.41%)
Mutual labels:  computational-geometry
mcut
A simple and fast library for mesh booleans and more.
Stars: ✭ 57 (-9.52%)
Mutual labels:  computational-geometry
Book-list-of-computational-geometry-and-computer-graphics
Book list of computational geometry and computer graphics 计算几何和计算机图形学必读书单与经典书籍
Stars: ✭ 374 (+493.65%)
Mutual labels:  computational-geometry
PGS
Processing Geometry Suite
Stars: ✭ 39 (-38.1%)
Mutual labels:  computational-geometry
polyclip
R package polyclip: a port of the Clipper library for polygon geometry
Stars: ✭ 18 (-71.43%)
Mutual labels:  computational-geometry

pyobb

Build Status PyPI version

OBB implementation in Python (using numpy)

This is basically a port of the code found on James' Blog, which in turn is a C++ implementation (using CGAL) of the ideas found in Stefan Gottschalk's PhD thesis. The central idea of this OBB contruction is to compute a covariance matrix for a point set and then find the eigenvectors of this covariance matrix.


Installation

Simply run

pip install pyobb

Usage

The pyobb package contains a single class: OBB. An OBB has the following attributes:

  • centroid: the OBB center
  • min: the OBB point with the smallest XYZ components in the local frame (i.e., -[width/2, height/2, depth/2])
  • max: the OBB point with the largest XYZ components in the local frame (i.e., [width/2, height/2, depth/2])
  • points: the 8 points of the OBB
  • extents: the extents of the OBB in the XYZ-axis (i.e., the scaled unit vectors of the global frame)
  • rotation: the rotation matrix of the OBB

You have three different ways to build an OBB: using a covariance matrix, using a point set and using a triangle mesh. Those ways are respectively implemented by the methods:

  • OBB.build_from_covariance_matrix(covariance_matrix, points): expects a 3x3 covariance matrix and a set of 3D points
  • OBB.build_from_points(points): expects a set of 3D points
  • OBB.build_from_triangles(points, triangles): expects a set of 3D points and a flat list of indices refering those points for which every 3-uple would form a triangle

For instance, you can create an OBB from the points of a lat/lon sphere

from math import pi, cos, sin, sqrt
from pyobb.obb import OBB

# creates a lat/lon sphere with a given radius and centered at a given point
def sphere(radius, center, num_slices=30):
    theta_step = 2.0 * pi / (num_slices - 1)
    phi_step = pi / (num_slices - 1.0)
    theta = 0.0
    vertices = []
    for i in range(0, num_slices):
        cos_theta = cos(theta)
        sin_theta = sin(theta)
        phi = 0.0
        for j in range(0, num_slices):
            x = -sin(phi) * cos_theta
            y = -cos(phi)
            z = -sin(phi) * sin_theta
            n = sqrt(x * x + y * y + z * z)
            if n < 0.99 or n > 1.01:
                x /= n
                y /= n
                z /= n
            vertices.append((x * radius + center[0],
                             y * radius + center[1],
                             z * radius + center[2]))
            phi += phi_step
        theta += theta_step
    return vertices

obb = OBB.build_from_points(sphere(1, (0, 0, 0)))

Which gives you this OBB:

You can also create an OBB from the vertices and faces of OBJ models

from pyobb.obb import OBB
from objloader import OBJ  # source: http://www.pygame.org/wiki/OBJFileLoader

obj = OBJ(filename='bunny.obj')  # stanford bunny
# obj = OBJ(filename='killeroo.obj')  # killeroo
indices = []
for face in obj.faces:
    indices.append(face[0][0] - 1)
    indices.append(face[0][1] - 1)
    indices.append(face[0][2] - 1)
obb = OBB.build_from_triangles(obj.vertices, indices)

Which gives you something like this:

or this:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].