Skip to content

Commit

Permalink
add checksums to docker builds and fix align_vectors test
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Dec 1, 2018
1 parent 7600e47 commit 67a5135
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 29 deletions.
2 changes: 2 additions & 0 deletions docker/builds/apt.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ apt-get install -y --no-install-recommends blender openscad wget bzip2 superviso

# get teigha converter for DWG to DXF conversion
wget https://download.opendesign.com/guestfiles/ODAFileConverter/ODAFileConverter_QT5_lnxX64_4.7dll.deb --no-check-certificate --quiet -O teigha.deb
echo "a9ca9c72e6303bc0a03b8b7f64a7300fec6092184f7efb2c8a89aca8d34ec32b teigha.deb" | sha256sum --check

dpkg -i teigha.deb
rm teigha.deb

Expand Down
3 changes: 3 additions & 0 deletions docker/builds/conda.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ set -xe

cd
wget https://repo.anaconda.com/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh --no-check-certificate --quiet -O miniconda.sh
# we ignored certs look at a checksum
echo "80ecc86f8c2f131c5170e43df489514f80e3971dd105c075935470bbf2476dea miniconda.sh" | sha256sum --check

bash miniconda.sh -b -p ~/conda
rm miniconda.sh

Expand Down
2 changes: 2 additions & 0 deletions docker/builds/vhacd.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ set -xe

# grab the VHACD (convex segmenter) binary
wget --no-check-certificate https://github.com/mikedh/v-hacd-1/raw/master/bin/linux/testVHACD
# check the hash of the downloaded file
echo "e1e79b2c1b274a39950ffc48807ecb0c81a2192e7d0993c686da90bd33985130 testVHACD" | sha256sum --check
# make it executable
chmod +x testVHACD
# move it into PATH
Expand Down
13 changes: 8 additions & 5 deletions tests/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ def test_align(self):
g.trimesh.util.generate_basis(target)))
for vector in vectors:
T, a = align(vector, target, return_angle=True)
result = g.np.dot(T, g.np.append(vector, 1))[:3]
aligned = g.np.linalg.norm(result - target) < 1e8
assert aligned
# rotate vector with transform
check = g.np.dot(T[:3, :3], vector)
# compare to target vector
norm = g.np.linalg.norm(check - target)
assert norm < 1e-8

# these vectors should be perpendicular and zero
angles = [align(i, target, return_angle=True)[1]
Expand Down Expand Up @@ -92,8 +94,9 @@ def test_align(self):

# check to make sure returned transform is correct
check = g.np.dot(T, g.np.append(vector, 1))[:3]
aligned = g.np.linalg.norm(check - vector[0]) < 1e8
assert aligned
norm = g.np.linalg.norm(check - vectors[0])

assert norm < 1e-8


if __name__ == '__main__':
Expand Down
70 changes: 47 additions & 23 deletions trimesh/inertia.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Functions for dealing with inertia tensors.
Results validated against known geometries and for internal
consistency.
Results validated against known geometries and checked for
internal consistency.
"""

import numpy as np
Expand All @@ -23,14 +23,19 @@ def cylinder_inertia(mass, radius, height, transform=None):
Parameters
------------
mass: float, mass of cylinder
radius: float, radius of cylinder
height: float, height of cylinder
transform: (4,4) float, transformation of cylinder
mass : float
Mass of cylinder
radius : float
Radius of cylinder
height : float
Height of cylinder
transform : (4,4) float
Transformation of cylinder
Returns
------------
inertia: (3,3) float, inertia tensor
inertia : (3,3) float
Inertia tensor
"""
h2, r2 = height ** 2, radius ** 2
diagonal = np.array([((mass * h2) / 12) + ((mass * r2) / 4),
Expand All @@ -50,12 +55,15 @@ def sphere_inertia(mass, radius):
Parameters
------------
mass: float, mass of sphere
radius: float, radius of sphere
mass : float
Mass of sphere
radius : float
Radius of sphere
Returns
------------
inertia: (3,3) float, inertia tensor
inertia : (3, 3) float
Inertia tensor
"""
inertia = (2.0 / 5.0) * (radius ** 2) * mass * np.eye(3)
return inertia
Expand All @@ -68,21 +76,28 @@ def principal_axis(inertia):
Parameters
------------
inertia: (3,3) float, inertia tensor
inertia : (3,3) float
Inertia tensor
Returns
------------
components: (3,) float, principal components of inertia
vectors: (3,3) float, row vectors pointing along
the principal axes of inertia
components : (3,) float
Principal components of inertia
vectors : (3,3) float
Row vectors pointing along the
principal axes of inertia
"""
inertia = np.asanyarray(inertia, dtype=np.float64)
if inertia.shape != (3, 3):
raise ValueError('inertia tensor must be (3,3)!')

# you could any of the following to calculate this:
# np.linalg.svd, np.linalg.eig, np.linalg.eigh
# moment of inertia is square symmetric matrix
# eigh has the best numeric precision in tests
components, vectors = np.linalg.eigh(inertia * negate_nondiagonal)

# eig returns them as column vectors, change them to row vectors
# eigh returns them as column vectors, change them to row vectors
vectors = vectors.T

return components, vectors
Expand All @@ -97,13 +112,17 @@ def transform_inertia(transform, inertia_tensor):
Parameters
------------
transform: (3,3) or (4,4) float, transformation matrix
inertia_tensor: (3,3) float, inertia tensor
transform : (3, 3) or (4, 4) float
Transformation matrix
inertia_tensor : (3, 3) float
Inertia tensor
Returns
------------
transformed: (3,3) float, inertia tensor in new frame
transformed : (3, 3) float
Inertia tensor in new frame
"""
# check inputs and extract rotation
transform = np.asanyarray(transform, dtype=np.float64)
if transform.shape == (4, 4):
rotation = transform[:3, :3]
Expand All @@ -129,12 +148,17 @@ def radial_symmetry(mesh):
Returns
-----------
symmetry: None No rotational symmetry
'radial' Symmetric around an axis
'spherical' Symmetric around a point
axis: None, or (3,) float
section: None, or (3, 2) float
symmetry : None or str
None No rotational symmetry
'radial' Symmetric around an axis
'spherical' Symmetric around a point
axis : None or (3,) float
Rotation axis or point
section : None or (3, 2) float
If radial symmetry provide vectors
to get cross section
"""

# if not a volume this is meaningless
if not mesh.is_volume:
return None, None, None
Expand Down
2 changes: 1 addition & 1 deletion trimesh/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.35.42'
__version__ = '2.35.43'

0 comments on commit 67a5135

Please sign in to comment.