Skip to content

Commit 2cb0e2c

Browse files
committed
Fix error in lamba return value from intersect_plane, make this computation its own method
1 parent 7382390 commit 2cb0e2c

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

spatialmath/geom3d.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ def pp(self):
451451
:seealso: Plucker.ppd, Plucker.point
452452
"""
453453

454-
return np.cross(self.v, self.w) / np.dot(self.w, self.w)
454+
return np.cross(self.v, self.w) / np.dot(self.w, self.w)
455+
455456
@property
456457
def ppd(self):
457458
"""
@@ -487,6 +488,9 @@ def point(self, lam):
487488
lam = base.getvector(lam, out='row')
488489
return self.pp.reshape((3,1)) + self.uw.reshape((3,1)) * lam
489490

491+
def lam(self, point):
492+
return np.dot( point.flatten() - self.pp, self.uw)
493+
490494
# ------------------------------------------------------------------------- #
491495
# TESTS ON PLUCKER OBJECTS
492496
# ------------------------------------------------------------------------- #
@@ -596,7 +600,6 @@ def __or__(self, l2): # pylint: disable=no-self-argument
596600
l1 = self
597601
return l1.isparallel(l2)
598602

599-
600603
def __xor__(self, l2): # pylint: disable=no-self-argument
601604

602605
"""
@@ -853,7 +856,7 @@ def intersect_plane(self, plane): # pylint: disable=no-self-argument
853856
# P = -(np.cross(line.v, plane.n) + plane.d * line.w) / den
854857
p = (np.cross(self.v, plane.n) - plane.d * self.w) / den
855858

856-
t = np.dot( self.pp - p, plane.n)
859+
t = self.lam(p)
857860
return namedtuple('intersect_plane', 'p lam')(p, t)
858861
else:
859862
return None

tests/test_geom3d.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,24 @@ def test_line(self):
239239
# side
240240
pass
241241

242-
def test_point(self):
242+
def test_contains(self):
243243
P = [2, 3, 7]
244244
Q = [2, 1, 0]
245245
L = Plucker.PQ(P, Q)
246246

247247
self.assertTrue( L.contains(L.point(0)) )
248248
self.assertTrue( L.contains(L.point(1)) )
249249
self.assertTrue( L.contains(L.point(-1)) )
250-
250+
251+
def test_point(self):
252+
P = [2, 3, 7]
253+
Q = [2, 1, 0]
254+
L = Plucker.PQ(P, Q)
255+
256+
nt.assert_array_almost_equal(L.point(0).flatten(), L.pp)
257+
258+
for x in (-2, 0, 3):
259+
nt.assert_array_almost_equal(L.lam(L.point(x)), x)
251260

252261
def test_char(self):
253262
P = [2, 3, 7]
@@ -257,6 +266,7 @@ def test_char(self):
257266
s = str(L)
258267
self.assertIsInstance(s, str)
259268

269+
260270
def test_plane(self):
261271

262272
xyplane = [0, 0, 1, 0]

0 commit comments

Comments
 (0)