from sympy.geometry import *
# Define a Line given two points p1 and p2.
p1 = Point(-694310.42867240659, 7051910.5392115889)
p2 = Point(-694286.161023414, 7051916.4164796043)
l = Line(p1, p2)
# Get the Segment perpendicular to l given p.
p = Point(-694210.80222825997, 7051914.7562929001)
s = l.perpendicular_segment(p)
distance = s.length
This throws the following error
In [61]: s = l.perpendicular_segment(p)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (102, 0))
In my attempt to figure out why this error is happening I devised the
below test.
l2 = l.perpendicular_line(p)
l.is_perpendicular(l2)
Out[56]: False
You might ask why my points have such large co-ordinates? They are
Points using the Google Spherical Merchant projection. As I said
originally I have been using PostGis and Django Geos for a long time.
This is the format of data that I work with.
Any ideas?
Kind Regards,
Cathal
What is the Google Spherical Merchant projection? I searched for it
on Google, but the only exact match I found was this thread.
Aaron Meurer
>
> Any ideas?
>
> Kind Regards,
> Cathal
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>
>
when I execute your code I get the error: TypeError: sympify() got an
unexpected keyword argument 'rational'.
I installed sympy using apt-get install python-sympy and synaptic
reports 0.6.7-1.1 as the installed version.
When I execute ?S I don't see any options for rational.
Call def: S(a, locals=None, convert_xor=True)
The same is true for nsimplify(2.3, rational=1)
from sympy import nsimplify
nsimplify(2.3, rational=1)
TypeError: nsimplify() got an unexpected keyword argument 'rational'
Again executing ?nsimplify mentions no rational param.
Definition: nsimplify(expr, constants=[], tolerance=None, full=False)
Any ideas?
Cathal
from sympy.geometry import *
from sympy import S
def rat(d):
return S(str(d), rational=True)
p1 = Point(rat(-694310.42867240659), rat(7051910.5392115889))
TypeError: sympify() got an unexpected keyword argument 'rational'
I got it to work, solution is below. Thanks for all your help... sympy rocks!!!.
Cathal
import sympy
from sympy import Rational
# Convert to Rational
def rat(d):
return Rational(str(d))
# Calculate the perpendicular distance from the point (lat, lon) to
the line defined by the points (x1, y1) and (x2, y2).
def perpendicular_distance(x1, y1, x2, y2, lat, lon):
p1 = sympy.geometry.Point(self.rat(x1), self.rat(y1))
p2 = sympy.geometry.Point(self.rat(x2), self.rat(y2))
l = sympy.geometry.Line(p1,p2)
p = sympy.geometry.Point(self.rat(lat), self.rat(lon))
s = l.perpendicular_segment(p)
return s.length.n()
Aaron Meurer