I didn't find any option to upload a file. I tried drag and drop but
it didn't work. So, I have to copy-paste the plotting.patch file.

# HG changeset patch
# User Saroj <[EMAIL PROTECTED]>
# Date 1199129707 21600
# Node ID 893074769cc1f0b8eb0c35efc8eb6cebe2faa1a7
# Parent  1ee1a59b01a6fa6ec1b0bf54a34bb4264c9eec68
added parseGeometryEntity method to plot.py and some code for Plot to
recognize and plot geometric entities
fixed tangent_line method in ellipse.py by swapping hradius and
vradius appropriately
added plot_interval method to ellipse, line, and line segment required
for geometric plot

diff -r 1ee1a59b01a6 -r 893074769cc1 sympy/geometry/ellipse.py
--- a/sympy/geometry/ellipse.py Sun Dec 30 23:13:36 2007 +0300
+++ b/sympy/geometry/ellipse.py Mon Dec 31 13:35:07 2007 -0600
@@ -83,8 +83,8 @@ class Ellipse(GeometryEntity):
         None if no tangent line is possible (e.g., p inside ellipse).
         """
         if p in self:
-            rise = (self.hradius ** 2)*(self.center[0] - p[0])
-            run = (self.vradius ** 2)*(p[1] - self.center[1])
+            rise = (self.vradius ** 2)*(self.center[0] - p[0])
+            run = (self.hradius ** 2)*(p[1] - self.center[1])
             p2 = Point(simplify(p[0] + run),
                        simplify(p[1] + rise))
             return Line(p, p2)
@@ -120,6 +120,10 @@ class Ellipse(GeometryEntity):
         return Point(
                 self.center[0] + self.hradius*Basic.cos(t),
                 self.center[1] + self.vradius*Basic.sin(t))
+
+    def plot_interval(self, parameter_name='t'):
+       t = Basic.Symbol(parameter_name, real=True)
+       return [t, -S.Pi, S.Pi]

     def random_point(self):
         """Returns a random point on the ellipse."""
diff -r 1ee1a59b01a6 -r 893074769cc1 sympy/geometry/line.py
--- a/sympy/geometry/line.py    Sun Dec 30 23:13:36 2007 +0300
+++ b/sympy/geometry/line.py    Mon Dec 31 13:35:07 2007 -0600
@@ -342,6 +342,11 @@ class Line(LinearEntity):
         y = simplify(self.p1[1] + t*(self.p2[1] - self.p1[1]))
         return Point(x, y)

+    def plot_interval(self, parameter_name='t'):
+       """Returns the plot interval for the default geometric plot of a
line."""
+       t = Basic.Symbol(parameter_name, real=True)
+       return [t, -5, 5]
+
     def equation(self, xaxis_name='x', yaxis_name='y'):
         """
         Returns the equation for this line. Optional parameters
xaxis_name
@@ -460,6 +465,17 @@ class Segment(LinearEntity):
             p1, p2 = p2, p1
         return LinearEntity.__new__(cls, p1, p2, **kwargs)

+    def arbitrary_point(self, parameter_name='t'):
+        """Returns a symbolic point that is on this line."""
+        t = Basic.Symbol(parameter_name, real=True)
+        x = simplify(self.p1[0] + t*(self.p2[0] - self.p1[0]))
+        y = simplify(self.p1[1] + t*(self.p2[1] - self.p1[1]))
+        return Point(x, y)
+
+    def plot_interval(self, parameter_name='t'):
+       t = Basic.Symbol(parameter_name, real=True)
+       return [t, 0, 1]
+
     def perpendicular_bisector(self, p=None):
         """
         Returns the perpendicular bisector of this segment. If no
point is
diff -r 1ee1a59b01a6 -r 893074769cc1 sympy/plotting/plot.py
--- a/sympy/plotting/plot.py    Sun Dec 30 23:13:36 2007 +0300
+++ b/sympy/plotting/plot.py    Mon Dec 31 13:35:07 2007 -0600
@@ -13,6 +13,9 @@ from time import sleep
 from time import sleep
 from os import getcwd, listdir
 from util import parse_option_string
+
+from sympy.geometry.entity import GeometryEntity
+from sympy.geometry.polygon import Polygon

 class Plot(object):
     """
@@ -216,7 +219,7 @@ class Plot(object):
         self.axes = PlotAxes(**axe_options)
         self._pobjects.append(self.axes)

-        self[0] = fargs
+        self.__setitem__(0, fargs)
         if win_args.get('visible', True):
             self.show()

@@ -284,20 +287,27 @@ class Plot(object):
         if isinstance(args, PlotObject):
             f = args
         else:
+
+           args = self.parseGeometryEntity(i, args)
+
             if not isinstance(args, (list, tuple)):
                 args = [args]
             if len(args) == 0:
                 return # no arguments given
-            kwargs = dict(bounds_callback=self.adjust_all_bounds)
+
+           kwargs = dict(bounds_callback=self.adjust_all_bounds)
             f = PlotMode(*args, **kwargs)

         if f:
-            self._render_lock.acquire()
-            self._functions[i] = f
-            self._render_lock.release()
+           self.set_function(i, f)
         else:
             raise ValueError("Failed to parse '%s'."
                     % ', '.join(str(a) for a in args))
+
+    def set_function(self, i, f):
+       self._render_lock.acquire()
+       self._functions[i] = f
+       self._render_lock.release()

     def __delitem__(self, i):
         """
@@ -309,6 +319,43 @@ class Plot(object):
         self.adjust_all_bounds()
         self._render_lock.release()

+    def parseGeometryEntity(self, i, args):
+       """
+       Workaround for Plot to recognize geometric entities
+       from the geometry module and plot them
+       """
+       if isinstance(args, (GeometryEntity, Polygon)):
+           args=(args,)
+       if len(args)>0 and isinstance(args[0], Polygon):
+           """
+           Plots a polygon by plotting the sides of the polygon,
+           which are line segments. For e.g. if you do
+           p = Plot(axes="label_axes=True")
+           p[0] = RegularPolygon(Point(0,1), 2, 6)
+           a hexagon is plotted as six line segments, and
+           p[0]...p[5] will be occupied. The next plot index of p
+           to be used without disturbing the hexagon will hence be 6.
+           """
+           entity = args
+           args = (entity[0].sides[0],)
+           for side in entity[0].sides[1:]:
+               interval = side.plot_interval()
+               fn = side.arbitrary_point()
+               side = [coords for coords in list(fn)]
+               side.append(interval)
+               kwargs = dict(bounds_callback=self.adjust_all_bounds)
+               self.set_function(i+1, PlotMode(*side, **kwargs))
+               i=i+1
+
+       if len(args)>0 and isinstance(args[0], GeometryEntity):
+           entity = args
+           args = [coords for coords in list(entity[0].arbitrary_point())]
+           args.append(entity[0].plot_interval())
+           if len(entity)>1:
+               args.append(entity[1:])    # add the remaining entries
+               args.remove(())    # remove the empty tuple entry at the end 
that
prevented extracting function and interval in some cases..
+       return args
+
     def firstavailableindex(self):
         """
         Returns the first unused index in the function list.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to