Skip to content

Commit

Permalink
Merge branch 'remove_array_padding'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hynes committed Mar 19, 2019
2 parents f74f7b7 + 65e7595 commit 71e16aa
Show file tree
Hide file tree
Showing 34 changed files with 842 additions and 540 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Project a point onto a line.
>>> line = Line(point=[0, 0], direction=[1, 1])

>>> line.project_point([5, 6, 7])
Point([5.5, 5.5, 0. ])
Point([5.5, 5.5])


An error is returned if the computation is undefined.
Expand Down
27 changes: 17 additions & 10 deletions doc/source/computations/comparison.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ True
False


Collinearity
------------

Check if multiple points are collinear.

>>> from skspatial.objects import Points

>>> Points(([0, 0], [1, 2, 3], [2, 4, 6])).are_collinear()
True

>>> Points(([0, 0], [1, 2, 3], [5, 2])).are_collinear()
False

>>> Points(([0, 0], [1, 2], [5, 2], [6, 3])).are_collinear()
False


Coplanarity
-----------

Expand All @@ -53,13 +70,3 @@ True
False


Collinearity
------------

Check if three points are collinear.

>>> Point([0, 0]).is_collinear([1, 1], [8, 8])
True

>>> Point([-1, 0]).is_collinear([1, 1], [8, 8])
False
2 changes: 1 addition & 1 deletion doc/source/computations/intersection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The intersection of a `Line` with a `Line` is a `Point`.
>>> line_b = Line([10, 0], [0, 1])

>>> line_a.intersect_line(line_b)
Point([10., 10., 0.])
Point([10., 10.])


In order to intersect, the lines must be coplanar and not parallel. An error is returned otherwise.
Expand Down
6 changes: 3 additions & 3 deletions doc/source/computations/projection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Project a vector onto a vector.
>>> vector_a = Vector([1, 0])

>>> vector_a.project([22, 9]) # Project vector B onto vector A.
Vector([22., 0., 0.])
Vector([22., 0.])


Point-Line Projection
Expand All @@ -25,7 +25,7 @@ Project a point onto a line.
>>> line = Line(point=[0, 0], direction=[1, 1])

>>> line.project_point([5, 5, 3])
Point([5., 5., 0.])
Point([5., 5.])


Point-Plane Projection
Expand All @@ -35,7 +35,7 @@ Project a point onto a plane.

>>> from skspatial.objects import Plane

>>> plane = Plane(point=[0, 0, 0], normal=[0, 0, 2])
>>> plane = Plane(point=[0, 0], normal=[0, 0, 2])

>>> plane.project_point([5, 9, -3])
Point([5., 9., 0.])
Expand Down
6 changes: 3 additions & 3 deletions doc/source/objects/line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ A line is defined by a point and a direction vector. The direction of the line i

>>> from skspatial.objects import Line

>>> line_1 = Line(point=[0, 0], direction=[5, 0])
>>> line_1 = Line(point=[0], direction=[5, 0])

>>> line_1
Line(point=Point([0., 0., 0.]), direction=Vector([1., 0., 0.]))
Line(point=Point([0., 0.]), direction=Vector([1., 0.]))


Alternatively, a `Line` can be defined by two points.
Expand Down Expand Up @@ -38,5 +38,5 @@ The distance from a `Point` to a `Line` can be found.
A `Point` can be projected onto a `Line`, returning a new `Point`.

>>> line_1.project_point([50, 20])
Point([50., 0., 0.])
Point([50., 0.])

33 changes: 10 additions & 23 deletions doc/source/objects/point_vector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,17 @@ True
The `Point` and `Vector` are both subclasses of the NumPy `ndarray`, which gives them all the functionality of a regular NumPy array.

>>> point_1.size
3
2

>>> point_1.shape
(3,)
(2,)


The input `array_like` must have a length of one to three. However, zeros are padded to the end so that the `Point` or `Vector` is always 3D. This is done for two main reasons:

- It ensures that the `Point` and `Vector` objects always have the same dimension.
- It ensures that the output of `np.cross` is also a 3D array.

>>> Point([1])
Point([1., 0., 0.])
Point([1.])

>>> Point([1, 2])
Point([1., 2., 0.])

>>> Point([1, 1, 1])
Point([1., 1., 1.])

>>> Point([1, 1, 1, 1])
Traceback (most recent call last):
...
dpcontracts.PreconditionError: The input length must be one to three.
Point([1., 2.])


A `Point` can be viewed as a position in space, and a `Vector` as an arrow through space.
Expand All @@ -55,32 +42,32 @@ Thus, a `Point` plus a `Vector` returns a `Point`.
>>> from skspatial.objects import Vector

>>> Point([-5, 8]).add(Vector([1, 1]))
Point([-4., 9., 0.])
Point([-4., 9.])


A `Vector` plus a `Vector` returns another `Vector`.

>>> Vector([1, 1]).add(Vector([2, -5]))
Vector([ 3., -4., 0.])
Vector([ 3., -4.])


A `Vector` has a magnitude attribute.
The magnitude of the vector is found with the `norm` method.

>>> vector = Vector([1, 1])
>>> vector.magnitude.round(3)
>>> vector.norm().round(3)
1.414

The unit vector can also be obtained.

>>> vector_unit = vector.unit()

>>> vector_unit.round(3)
array([0.707, 0.707, 0. ])
array([0.707, 0.707])

One vector can be projected onto another.

>>> vector_u = Vector([1, 0])
>>> vector_v = Vector([5, 9])

>>> vector_u.project(vector_v) # Project vector v onto vector u.
Vector([5., 0., 0.])
Vector([5., 0.])
2 changes: 1 addition & 1 deletion skspatial/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def area_triangle(point_a, point_b, point_c):

vector_cross = vector_ab.cross(vector_ac)

return 0.5 * vector_cross.magnitude
return 0.5 * vector_cross.norm()


@ensure("The output must be zero or greater.", lambda _, result: result >= 0)
Expand Down
4 changes: 2 additions & 2 deletions skspatial/objects/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .point import Point
from .point import Point, Points
from .vector import Vector
from .line import Line
from .plane import Plane

__all__ = ['Point', 'Vector', 'Line', 'Plane']
__all__ = ['Point', 'Points', 'Vector', 'Line', 'Plane']

0 comments on commit 71e16aa

Please sign in to comment.