I just fixed the bug which is in sympy\geometry\line3d.py:
def intersection(self, o):
.......
elif isinstance(o, LinearEntity3D):
a = self.direction_cosine
b = o.direction_cosine
a = [abs(i) for i in a]
b = [abs(i) for i in b]
if a == b: # assume they are parallel
if isinstance(self, Line3D):
......
Obviously, "if a == b" can not guarantee a is parallel to b. So, two
more conditions need to be added for parallel checking:
c1 = sum(1 for i in range(len(a)) if a[i]==-b[i])
c2 = sum(1 for i in range(len(a)) if a[i]==b[i])
a = [abs(i) for i in a]
b = [abs(i) for i in b]
if a == b and (c1==3 or c2==3): # assume they are parallel
if isinstance(self, Line3D):
....
I have tested it with several examples and it works now.
ouyang
On Wednesday, November 26, 2014 4:41:16 AM UTC+8, Chris Smith wrote:
> That's a bug.
>
> On Tuesday, November 25, 2014 7:58:16 AM UTC-6, zxo102 wrote:
>>
>> Hi there,
>> In sympy0.7.6 and python3.4, I would like find a intersection point for
>> two 3D lines but failed at the following 3D case.
>>
>> 2D case:
>>
>> >>> from sympy import Line, Point
>> >>> l1 = Line(Point(4,0),Point(0,4))
>> >>> l2 = Line(Point(0,0),Point(4,4))
>> >>> l1.intersection(l2)
>> [Point(2, 2)]
>>
>> 3D case: add z=1 into the above coordinates
>>
>> >>> from sympy import Line3D, Point3D
>> >>> l3 = Line3D(Point3D(4,0,1),Point3D(0,4,1))
>> >>> l4 = Line3D(Point3D(0,0,1),Point3D(4,4,1))
>> >>> l3.intersection(l4)
>> []
>>
>> l3.intersection(l4) should return [Point3D(2,2,1)].
>>
>> Is this a bug? or I did something wrong with it? Thanks for your help.
>>
>> ouyang
>>
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/593bf887-70ee-4a4e-8aac-a1817ac8fe75%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.