8000 Line3, improve doco, add additional constructors · astyl/spatialmath-python@667f19b · GitHub
[go: up one dir, main page]

Skip to content

Commit 667f19b

Browse files
committed
Line3, improve doco, add additional constructors
1 parent 5ac7c90 commit 667f19b

File tree

1 file changed

+60
-7
lines changed

1 file changed

+60
-7
lines changed

spatialmath/geom3d.py

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,54 @@ def LinePoint(cls, l, p):
9292
d = np.dot(l.v, p)
9393

9494
return cls(n, d)
95+
96+
@classmethod
97+
def TwoLines(cls, l1, l2):
98+
"""
99+
Create a plane object from two line
100+
101+
:param l1: 3D line
102+
:type l1: Line3
103+
:param l2: 3D line
104+
:type l2: Line3
105+
:return: a Plane object
106+
:rtype: Plane
107+
108+
.. warning:: This algorithm fails if the lines are parallel.
109+
110+
:seealso: :meth:`LinePoint` :meth:`PointNormal` :meth:`ThreePoints`
111+
"""
112+
n = np.cross(l1.w, l2.w)
113+
d = np.dot(l1.v, l2.w)
95114

115+
return cls(n, d)
116+
117+
@staticmethod
118+
def intersection(pi1, pi2, pi3):
119+
"""
120+
Intersection point of three planes
121+
122+
:param pi1: plane 1
123+
:type pi1: Plane
124+
:param pi2: plane 2
125+
:type pi2: Plane
126+
:param pi3: plane 3
127+
:type pi3: Plane
128+
:return: coordinates of intersection point
129+
:rtype: ndarray(3)
130+
131+
This static method computes the intersection point of the three planes
132+
given as arguments.
133+
134+
.. warning:: This algorithm fails if the planes do not intersect, or
135+
intersect along a line.
136+
137+
:seealso: :meth:`Plane`
138+
"""
139+
A = np.vstack([pi1.n, pi2.n, pi3.n])
140+
b = np.array([pi1.d, pi2.d, pi3.d])
141+
return np.linalg.det(A) @ b
142+
96143
@property
97144
def n(self):
98145
r"""
@@ -210,27 +257,27 @@ def __init__(self, v=None, w=None):
210257
211258
A representation of a 3D line using Plucker coordinates.
212259
213-
- ``Line3(P)`` creates a 3D line from a Plucker coordinate vector ``[v, w]``
260+
- ``Line3(p)`` creates a 3D line from a Plucker coordinate vector ``p=[v, w]``
214261
where ``v`` (3,) is the moment and ``w`` (3,) is the line direction.
215262
216263
- ``Line3(v, w)`` as above but the components ``v`` and ``w`` are
217264
provided separately.
218265
219266
- ``Line3(L)`` creates a copy of the ``Line3`` object ``L``.
220267
221-
.. note::
268+
:notes:
222269
223270
- The ``Line3`` object inherits from ``collections.UserList`` and has list-like
224271
behaviours.
225-
- A single ``Line3`` object contains a 1D array of Plucker coordinates.
272+
- A single ``Line3`` object contains a 1D-array of Plucker coordinates.
226273
- The elements of the array are guaranteed to be Plucker coordinates.
227274
- The number of elements is given by ``len(L)``
228275
- The elements can be accessed using index and slice notation, eg. ``L[1]`` or
229276
``L[2:3]``
230277
- The ``Line3`` instance can be used as an iterator in a for loop or list comprehension.
231278
- Some methods support operations on the internal list.
232279
233-
:seealso: :meth:`TwoPoints` :meth:`Planes` :meth:`PointDir`
280+
:seealso: :meth:`Join` :meth:`TwoPlanes` :meth:`PointDir`
234281
"""
235282
super().__init__() # enable list powers
236283

@@ -285,7 +332,7 @@ def Join(cls, P=None, Q=None):
285332
return cls(np.r_[v, w])
286333

287334
@classmethod
288-
def IntersectingPlanes(cls, pi1, pi2):
335+
def TwoPlanes(cls, pi1, pi2):
289336
r"""
290337
Create 3D line from intersection of two planes
291338
@@ -296,7 +343,7 @@ def IntersectingPlanes(cls, pi1, pi2):
296343
:return: 3D line
297344
:rtype: ``Line3`` instance
298345
299-
``L = Plucker.IntersectingPlanes(π1, π2)`` is a Plucker object that represents
346+
``L = Line3.TwoPlanes(π1, π2)`` is a ``Line3`` object that represents
300347
the line formed by the intersection of two planes ``π1`` and ``π3``.
301348
302349
Planes are represented by the 4-vector :math:`[a, b, c, d]` which describes
@@ -316,6 +363,12 @@ def IntersectingPlanes(cls, pi1, pi2):
316363
v = pi2.d * pi1.n - pi1.d * pi2.n
317364
return cls(np.r_[v, w])
318365

366+
@classmethod
367+
def IntersectingPlanes(cls, pi1, pi2):
368+
369+
warnings.warn('use TwoPlanes method instead', DeprecationWarning)
370+
return cls.TwolPlanes(pi1, pi2)
371+
319372
@classmethod
320373
def PointDir(cls, point, dir):
321374
"""
@@ -328,7 +381,7 @@ def PointDir(cls, point, dir):
328381
:return: 3D line
329382
:rtype: ``Line3`` instance
330383
331-
``Line3.pointdir(P, W)`` is a Plucker object that represents the
384+
``Line3.PointDir(P, W)`` is a `Line3`` object that represents the
332385
line containing the point ``P`` and parallel to the direction vector ``W``.
333386
334387
:seealso: :meth:`Join` :meth:`IntersectingPlanes`

0 commit comments

Comments
 (0)
0