mostly comments, but broke something
This commit is contained in:
parent
fc82bc255c
commit
3f8b9bef06
1 changed files with 366 additions and 127 deletions
|
|
@ -1,8 +1,17 @@
|
|||
from typing import List
|
||||
import numpy
|
||||
from numpy.linalg import norm
|
||||
|
||||
from . import poly_t, plane_t
|
||||
|
||||
def build_tetrahedron(vertices: numpy.ndarray):
|
||||
|
||||
def build_tetrahedron(vertices: numpy.ndarray) -> poly_t:
|
||||
'''
|
||||
Build a Schelegel-representation tetrahedron.
|
||||
|
||||
:param vertices: 4x3 array, representing the vertex coordinates.
|
||||
:return: Tetrahedron in Schelgel representation.
|
||||
'''
|
||||
poly = {
|
||||
'vertices': numpy.array(vertices, dtype=float),
|
||||
'neighbors': numpy.array((
|
||||
|
|
@ -14,7 +23,14 @@ def build_tetrahedron(vertices: numpy.ndarray):
|
|||
return poly
|
||||
|
||||
|
||||
def build_box(rbounds):
|
||||
def build_box(box_corners: numpy.ndarray) -> poly_t:
|
||||
'''
|
||||
Build a Schelegel-representation box.
|
||||
|
||||
:param box_corners: 2x3 array, representing the vertex coordinates of
|
||||
two diagonally-opposite corners of the box.
|
||||
:return: Box in Schelgel representation.
|
||||
'''
|
||||
neighbors = [
|
||||
[1, 4, 3],
|
||||
[2, 5, 0],
|
||||
|
|
@ -27,14 +43,14 @@ def build_box(rbounds):
|
|||
]
|
||||
|
||||
vertices = [
|
||||
[rbounds[0, 0], rbounds[0, 1], rbounds[0, 2]],
|
||||
[rbounds[1, 0], rbounds[0, 1], rbounds[0, 2]],
|
||||
[rbounds[1, 0], rbounds[1, 1], rbounds[0, 2]],
|
||||
[rbounds[0, 0], rbounds[1, 1], rbounds[0, 2]],
|
||||
[rbounds[0, 0], rbounds[0, 1], rbounds[1, 2]],
|
||||
[rbounds[1, 0], rbounds[0, 1], rbounds[1, 2]],
|
||||
[rbounds[1, 0], rbounds[1, 1], rbounds[1, 2]],
|
||||
[rbounds[0, 0], rbounds[1, 1], rbounds[1, 2]],
|
||||
[box_corners[0, 0], box_corners[0, 1], box_corners[0, 2]],
|
||||
[box_corners[1, 0], box_corners[0, 1], box_corners[0, 2]],
|
||||
[box_corners[1, 0], box_corners[1, 1], box_corners[0, 2]],
|
||||
[box_corners[0, 0], box_corners[1, 1], box_corners[0, 2]],
|
||||
[box_corners[0, 0], box_corners[0, 1], box_corners[1, 2]],
|
||||
[box_corners[1, 0], box_corners[0, 1], box_corners[1, 2]],
|
||||
[box_corners[1, 0], box_corners[1, 1], box_corners[1, 2]],
|
||||
[box_corners[0, 0], box_corners[1, 1], box_corners[1, 2]],
|
||||
]
|
||||
|
||||
return {
|
||||
|
|
@ -43,20 +59,33 @@ def build_box(rbounds):
|
|||
}
|
||||
|
||||
|
||||
def planes_from_box(rbounds: numpy.ndarray):
|
||||
def planes_from_box(box_corners: numpy.ndarray) -> List[plane_t]:
|
||||
'''
|
||||
Construct a list of planes corresponding to the faces of a box.
|
||||
|
||||
:param box_corners: 2x3 array, representing the vertex coordinates of
|
||||
two diagonally-opposite corners of the box.
|
||||
:return: List of planes, facing inwards.
|
||||
'''
|
||||
faces = [
|
||||
(( 0, 0, 1), -rbounds[0, 2]),
|
||||
(( 0, 0, -1), rbounds[1, 2]),
|
||||
(( 0, 1, 0), -rbounds[0, 1]),
|
||||
(( 0, -1, 0), rbounds[1, 1]),
|
||||
(( 1, 0, 0), -rbounds[0, 0]),
|
||||
((-1, 0, 0), rbounds[1, 0]),
|
||||
(( 0, 0, 1), -box_corners[0, 2]),
|
||||
(( 0, 0, -1), box_corners[1, 2]),
|
||||
(( 0, 1, 0), -box_corners[0, 1]),
|
||||
(( 0, -1, 0), box_corners[1, 1]),
|
||||
(( 1, 0, 0), -box_corners[0, 0]),
|
||||
((-1, 0, 0), box_corners[1, 0]),
|
||||
]
|
||||
|
||||
return [(numpy.array(n), d) for n, d in faces]
|
||||
|
||||
|
||||
def planes_from_tetrahedron(vertices: numpy.ndarray):
|
||||
def planes_from_tetrahedron(vertices: numpy.ndarray) -> List[plane_t]:
|
||||
'''
|
||||
Construct a list of planes corresponding to the faces of a tetrahedron.
|
||||
|
||||
:param vertices: 4x3 array, representing the vertex coordinates.
|
||||
:return: List of planes, facing inwards.
|
||||
'''
|
||||
verts = numpy.array(vertices, dtype=float)
|
||||
vset_inds = numpy.array((
|
||||
[3, 1, 2, 1],
|
||||
|
|
@ -73,4 +102,3 @@ def planes_from_tetrahedron(vertices: numpy.ndarray):
|
|||
d = -numpy.sum(n * centers, axis=1)
|
||||
|
||||
return [plane for plane in zip(n, d)]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue