[genius] Thu Oct 12 17:52:41 2017 Jiri (George) Lebl <jirka 5z com>
- From: George Lebl <jirka src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [genius] Thu Oct 12 17:52:41 2017 Jiri (George) Lebl <jirka 5z com>
- Date: Thu, 12 Oct 2017 22:53:06 +0000 (UTC)
commit 4b9b15126212fcf9e364a89c028f4d8b632bf98d
Author: Jiri (George) Lebl <jiri lebl gmail com>
Date: Thu Oct 12 17:52:51 2017 -0500
Thu Oct 12 17:52:41 2017 Jiri (George) Lebl <jirka 5z com>
* examples/plane-curves.gel: Simple brute force algorithm for
plotting plane curves.
ChangeLog | 5 +++
examples/Makefile.am | 3 +-
examples/plane-curves.gel | 83 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 90 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b2eafba..ae216d3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Oct 12 17:52:41 2017 Jiri (George) Lebl <jirka 5z com>
+
+ * examples/plane-curves.gel: Simple brute force algorithm for
+ plotting plane curves.
+
Thu Oct 12 17:22:01 2017 Jiri (George) Lebl <jirka 5z com>
* examples/strange-attractor.gel: make the variable names match the
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 0c09286..9fae979 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -35,7 +35,8 @@ example_DATA = \
riemann-integral.gel \
riemann-integral-darboux.gel \
plot-ode-runge-kutta.gel \
- plot-ode-trajectory-runge-kutta.gel
+ plot-ode-trajectory-runge-kutta.gel \
+ plane-curves.gel
EXTRA_DIST = \
$(example_DATA)
diff --git a/examples/plane-curves.gel b/examples/plane-curves.gel
new file mode 100644
index 0000000..fd130f8
--- /dev/null
+++ b/examples/plane-curves.gel
@@ -0,0 +1,83 @@
+# Category: Algebraic Geometry
+# Name: Plot plane curves
+#
+# Plot plane curves using a very simple algorithm, just go through a region as
+# a grid and notice sign changes, and put a point at the sign changes. Not
+# very efficient, but it does the job.
+
+# The cusp
+function f(x,y) = x^3-y^2;
+range = [-0.5,2.0,-2.0,2.0];
+
+# Folium of Descartes
+#function f(x,y) = x^3+y^3-3*x*y;
+#range = [-2.0,2.0,-2.0,2.0];
+
+# elliptic curve 1
+#function f(x,y) = x^3-2*x-y^2;
+#range = [-2.0,3.0,-3.0,3.0];
+
+# elliptic curve 2
+#function f(x,y) = x^3-2*x-y^2+2;
+#range = [-2.0,3.0,-3.0,3.0];
+
+# hyperbola
+#function f(x,y) = x^2-y^2-0.5;
+#range = [-2.0,2.0,-2.0,2.0];
+
+# egg
+#function f(x,y) = x^2+y^2*(1+0.4*x)-1;
+#range = [-2.0,2.0,-2.0,2.0];
+
+# hyperbola
+#function f(x,y) = x^2-y^2-0.5;
+#range = [-2.0,2.0,-2.0,2.0];
+
+# heart
+#function f(x,y) = (x^2+y^2-1)^3-x^2*y^3;
+#range = [-2.0,2.0,-1.5,1.8];
+
+# number of steps in each direction
+steps = 300;
+
+# compute the steps
+xstep = float(range@(2)-range@(1))/steps;
+ystep = float(range@(4)-range@(3))/steps;
+
+
+# prepare the canvas
+LinePlotWindow = range;
+LinePlotDrawLegends = false;
+
+LinePlotClear();
+PlotWindowPresent(); # Make sure the window is raised
+
+points = null;
+for xx = range@(1) to range@(2) by xstep do (
+ lastf = f(xx,range@(3));
+ for yy = range@(3)+ystep to range@(4) by ystep do (
+ newf = f(xx,yy);
+ if newf*lastf <= 0 then (
+ if (newf != lastf) then (
+ pr = |newf| / |newf-lastf|;
+ points = [points;[xx,yy-ystep*pr]]
+ ) else (
+ points = [points;[xx,yy];[xx,yy-ystep]]
+ )
+ );
+ rightf = f(xx+xstep,yy);
+ if newf*rightf <= 0 then (
+ if (newf != rightf) then (
+ pr = |newf| / |newf-rightf|;
+ points = [points;[xx+xstep*pr,yy]];
+ ) else (
+ points = [points;[xx,yy];[xx+xstep,yy]];
+ )
+ );
+ lastf = newf
+ );
+ LinePlotDrawPoints(points,"color","blue");
+ points = null
+);
+
+LinePlotDrawPoints(points,"color","blue");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]