Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
4f25091
adding change basis
romanarust Sep 30, 2019
d8dd4ed
update represent local/global with change_basis
romanarust Oct 2, 2019
a1484ff
small update on quaternion
romanarust Oct 3, 2019
1e92bd0
return quaternion
romanarust Oct 8, 2019
0ba2c02
returning vector from axis angle vector
romanarust Oct 8, 2019
7ceaac3
adding unitized and scaled to vector
romanarust Oct 8, 2019
e240212
fixing returns and docstrings
romanarust Oct 8, 2019
49fbf5b
added transform_frames, fix dehomogenize_numpy
romanarust Oct 9, 2019
60a985f
adding correct_axis_vectors
romanarust Oct 9, 2019
f6dbb9d
adding matrix_from_frame_to_frame and matrix_change_basis
romanarust Oct 10, 2019
5b1e600
Update matrices.py
romanarust Oct 11, 2019
c7be7f4
represent_(frames\points\vectors)_in_(local\global)_coordinate_system…
romanarust Oct 13, 2019
a042b4b
adding python equivalent of local/global_coords_numpy
romanarust Oct 13, 2019
8ac7680
change coordinates to coords
romanarust Oct 13, 2019
6431f0d
moving methods from helpers into coordinate_systems
romanarust Oct 13, 2019
5297d70
adding possiblility of passing another cs than worldXY
romanarust Oct 13, 2019
1a7b68e
fixing examples
romanarust Oct 13, 2019
fe9c659
changing global/local_coords_numpy to use frame instead of origin, uvw
romanarust Oct 13, 2019
4727666
removing unused local axes
romanarust Oct 13, 2019
5fbc34f
fixing examples
romanarust Oct 13, 2019
bbc0daa
Update coordinate_systems.py
romanarust Oct 13, 2019
1b49b4a
Update coordinate_systems.py
romanarust Oct 13, 2019
794b891
fixing docstrings
romanarust Oct 13, 2019
c30cce2
fixes because running tests
romanarust Oct 13, 2019
4310dc9
fix math backslash
romanarust Oct 13, 2019
0a1b913
adding change basis
romanarust Sep 30, 2019
8daa988
update represent local/global with change_basis
romanarust Oct 2, 2019
a42588b
small update on quaternion
romanarust Oct 3, 2019
4032c79
return quaternion
romanarust Oct 8, 2019
561a84e
returning vector from axis angle vector
romanarust Oct 8, 2019
eea3101
adding unitized and scaled to vector
romanarust Oct 8, 2019
b2461ec
fixing returns and docstrings
romanarust Oct 8, 2019
b1f4db4
added transform_frames, fix dehomogenize_numpy
romanarust Oct 9, 2019
ac8a20e
adding correct_axis_vectors
romanarust Oct 9, 2019
e9a42bf
adding matrix_from_frame_to_frame and matrix_change_basis
romanarust Oct 10, 2019
c95973e
Update matrices.py
romanarust Oct 11, 2019
35cf920
represent_(frames\points\vectors)_in_(local\global)_coordinate_system…
romanarust Oct 13, 2019
afcf5b2
adding python equivalent of local/global_coords_numpy
romanarust Oct 13, 2019
b4fb2fb
change coordinates to coords
romanarust Oct 13, 2019
ab592a7
moving methods from helpers into coordinate_systems
romanarust Oct 13, 2019
e2f507a
adding possiblility of passing another cs than worldXY
romanarust Oct 13, 2019
9fa984d
fixing examples
romanarust Oct 13, 2019
d5c283c
changing global/local_coords_numpy to use frame instead of origin, uvw
romanarust Oct 13, 2019
3cbb689
removing unused local axes
romanarust Oct 13, 2019
7137fb6
fixing examples
romanarust Oct 13, 2019
26d8650
Update coordinate_systems.py
romanarust Oct 13, 2019
0051ca3
Update coordinate_systems.py
romanarust Oct 13, 2019
fe1a906
fixing docstrings
romanarust Oct 13, 2019
33556b1
fixes because running tests
romanarust Oct 13, 2019
86b3431
fix math backslash
romanarust Oct 13, 2019
8e0739e
removing local\global coords now found in coordinate_systems
romanarust Oct 13, 2019
4130682
small update
romanarust Oct 13, 2019
ac29485
small fixes
romanarust Oct 13, 2019
5dc10ac
Merge branch 'update-frame-and-transformation' of https://github.com/…
romanarust Oct 13, 2019
988a423
adding matix_from_frame_to_frame and matrix_change_basis
romanarust Oct 14, 2019
aa36b19
removing helpers and coodinate_systems
romanarust Oct 14, 2019
c8791ee
removing duplicate change_basis
romanarust Oct 14, 2019
45e99a5
adding stuff from helpers and coordinate_systems in transformations
romanarust Oct 14, 2019
1e200e5
adding stuff from helpers and coordinate_systems in transformations_n…
romanarust Oct 14, 2019
19fc662
fixing local/global_coords and adding static method local_to_local_co…
romanarust Oct 14, 2019
ae1279c
autopep8
romanarust Oct 14, 2019
824e2ff
match to new frame method
romanarust Oct 14, 2019
a2ace6c
fix doctests
romanarust Oct 14, 2019
28fd1ef
removed based on change previous in time
romanarust Oct 14, 2019
887e2ee
note not needed anymore
romanarust Oct 14, 2019
7bb7372
Update CHANGELOG.md
romanarust Oct 14, 2019
2ed3c6c
Update CHANGELOG.md
romanarust Oct 14, 2019
7aa3f1e
Update CHANGELOG.md
romanarust Oct 14, 2019
9dd1fb2
r""" instead of """ at the start
romanarust Oct 15, 2019
61583d9
adding close to basic
romanarust Oct 15, 2019
0a91c50
changing global_coords to world_coords
romanarust Oct 15, 2019
807e68a
rename correct_axes to orthonormalize_axes
romanarust Oct 15, 2019
fbbfaea
change naming frame, world, local
romanarust Oct 18, 2019
ce8b53d
addind functions to __all__
romanarust Oct 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added `matrix_change_basis`, `Transformation.change_basis`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this not be matrix_from_basis_change or something like that?

Copy link
Member Author

@romanarust romanarust Oct 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better would be change_of_basis_matrix but that does not follow the other naming.
or matrix_to_change_basis?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha no, sorry, i misunderstood the point of the function...

- Added `matrix_from_frame_to_frame`
- Added non-numpy versions of `global_coords`, `local_coords`
- Added static method `Frame.local_to_local_coords`
- Added `__getitem__`, `__setitem__` and `__eq__` to `Quaternion`
- Added `Vector.scaled` and `Vector.unitized`
- Added `transform_frames` and respective helper functions `dehomogenize_and_unflatten_frames`, `homogenize_and_flatten_frames`
- Added `transform_frames_numpy` and respective helper functions `dehomogenize_and_unflatten_frames_numpy`, `homogenize_and_flatten_frames_numpy`

### Changed

- Changed parameters `origin` `uvw` of `global_coords_numpy` and `local_coords_numpy` to `frame`
- Fixed some returns of `Frame` and `Rotation` to use `Vector` or `Quaternion`
- Methods `Frame.represent_point/vector/frame_in_global_coordinates` and `Frame.represent_point/vector/frame_in_local_coordinates` are now `Frame.local_coords` and `Frame.global_coords`

### Removed


Expand Down
22 changes: 22 additions & 0 deletions src/compas/geometry/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from random import uniform

__all__ = [
'close',
'allclose',
'add_vectors',
'add_vectors_xy',
Expand Down Expand Up @@ -59,6 +60,27 @@
]


def close(value1, value2, tol=1e-05):
"""Returns True if two values are equal within a tolerance.

Parameters
----------
value1 : float or int
value2 : float or int
tol : float, optional
The tolerance for comparing values.
Default is ``1e-05``.

Examples
--------
>>> close(1., 1.001)
False
>>> close(1., 1.001, tol=1e-2)
True
"""
return fabs(value1 - value2) < tol


def allclose(l1, l2, tol=1e-05):
"""Returns True if two lists are element-wise equal within a tolerance.

Expand Down
47 changes: 14 additions & 33 deletions src/compas/geometry/bbox/bbox_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# from scipy.spatial import QhullError

from compas.geometry import local_axes
from compas.geometry import local_coords_numpy
from compas.geometry import global_coords_numpy
from compas.geometry import world_to_local_coords_numpy
from compas.geometry import local_to_world_coords_numpy


__all__ = [
Expand All @@ -27,7 +27,7 @@


def oriented_bounding_box_numpy(points):
"""Compute the oriented minimum bounding box of a set of points in 3D space.
r"""Compute the oriented minimum bounding box of a set of points in 3D space.

Parameters
----------
Expand Down Expand Up @@ -85,8 +85,8 @@ def oriented_bounding_box_numpy(points):
>>> a = length_vector(subtract_vectors(bbox[1], bbox[0]))
>>> b = length_vector(subtract_vectors(bbox[3], bbox[0]))
>>> c = length_vector(subtract_vectors(bbox[4], bbox[0]))
>>> a * b * c
30.0
>>> close(a * b * c, 30.)
True

"""
points = asarray(points)
Expand Down Expand Up @@ -114,7 +114,8 @@ def oriented_bounding_box_numpy(points):
a, b, c = points[simplex]
uvw = local_axes(a, b, c)
xyz = points[hull.vertices]
rst = local_coords_numpy(a, uvw, xyz)
frame = [a, uvw[0], uvw[1]]
rst = world_to_local_coords_numpy(frame, xyz)
dr, ds, dt = ptp(rst, axis=0)
v = dr * ds * dt

Expand All @@ -131,7 +132,7 @@ def oriented_bounding_box_numpy(points):
[rmax, smax, tmax],
[rmin, smax, tmax],
]
bbox = global_coords_numpy(a, uvw, bbox)
bbox = local_to_world_coords_numpy(frame, bbox)
volume = v

return bbox
Expand Down Expand Up @@ -191,7 +192,7 @@ def oriented_bounding_box_xy_numpy(points):
p1 = points[simplex[1]]

# s direction
s = p1 - p0
s = p1 - p0
sl = sum(s ** 2) ** 0.5
su = s / sl
vn = xy_hull - p0
Expand All @@ -204,7 +205,7 @@ def oriented_bounding_box_xy_numpy(points):
b1 = p0 + sc[scmax] * su

# t direction
t = array([-s[1], s[0]])
t = array([-s[1], s[0]])
tl = sum(t ** 2) ** 0.5
tu = t / tl
vn = xy_hull - p0
Expand Down Expand Up @@ -239,35 +240,15 @@ def oriented_bounding_box_xy_numpy(points):
if __name__ == "__main__":

import numpy
import math
from compas.geometry import bounding_box
from compas.geometry import subtract_vectors
from compas.geometry import length_vector
from compas.geometry import Rotation
from compas.geometry import transform_points_numpy
from compas.geometry import allclose
from compas.geometry import close

points = numpy.random.rand(10000, 3)
bottom = numpy.array([[0.0,0.0,0.0], [1.0,0.0,0.0], [0.0,1.0,0.0], [1.0,1.0,0.0]])
top = numpy.array([[0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [0.0, 1.0, 1.0], [1.0, 1.0, 1.0]])
points = numpy.concatenate((points, bottom, top))
points[:, 0] *= 10
points[:, 2] *= 3
import doctest
doctest.testmod(globs=globals())

bbox = bounding_box(points)
a = length_vector(subtract_vectors(bbox[1], bbox[0]))
b = length_vector(subtract_vectors(bbox[3], bbox[0]))
c = length_vector(subtract_vectors(bbox[4], bbox[0]))
v1 = a * b * c

R = Rotation.from_axis_and_angle([1.0, 1.0, 0.0], 0.5 * 3.14159)
points = transform_points_numpy(points, R.matrix)

bbox = oriented_bounding_box_numpy(points)

a = length_vector(subtract_vectors(bbox[1], bbox[0]))
b = length_vector(subtract_vectors(bbox[3], bbox[0]))
c = length_vector(subtract_vectors(bbox[4], bbox[0]))
v2 = a * b * c

print(v1, v2)
print(allclose([v1], [v2]))
9 changes: 5 additions & 4 deletions src/compas/geometry/bestfit/bestfit_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from scipy.optimize import leastsq

# should this not be defined in a different location?
from compas.geometry import local_coords_numpy
from compas.geometry import global_coords_numpy
from compas.geometry import world_to_local_coords_numpy
from compas.geometry import local_to_world_coords_numpy

from compas.numerical import pca_numpy

Expand Down Expand Up @@ -151,7 +151,8 @@ def bestfit_circle_numpy(points):

"""
o, uvw, _ = pca_numpy(points)
rst = local_coords_numpy(o, uvw, points)
frame = [o, uvw[1], uvw[2]]
rst = world_to_local_coords_numpy(frame, points)
x = rst[:, 0]
y = rst[:, 1]

Expand All @@ -172,7 +173,7 @@ def f(c):

print(residu)

xyz = global_coords_numpy(o, uvw, [[c[0], c[1], 0.0]])[0]
xyz = local_to_world_coords_numpy(frame, [[c[0], c[1], 0.0]])[0]

o = xyz.tolist()
u, v, w = uvw.tolist()
Expand Down
2 changes: 1 addition & 1 deletion src/compas/geometry/primitives/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from .point import Point
from .line import Line
from .plane import Plane
from .quaternion import Quaternion
from .frame import Frame

from .polyline import Polyline
from .polygon import Polygon
from .circle import Circle
from .curve import Bezier

from .quaternion import Quaternion

from .shapes import *

Expand Down
Loading