r5702 - developers/werner/cncmap/zmap

werner at docs.openmoko.org werner at docs.openmoko.org
Thu Oct 22 18:33:34 CEST 2009


Author: werner
Date: 2009-10-22 18:33:34 +0200 (Thu, 22 Oct 2009)
New Revision: 5702

Modified:
   developers/werner/cncmap/zmap/Makefile
   developers/werner/cncmap/zmap/zline.c
   developers/werner/cncmap/zmap/zmap.c
Log:
Fixed some of the algorithms (in progress).

- zmap/zmap.c (comp): sorting works so much better if we don't just compare
  things with themselves
- zmap/zline.c (next_closest): renormalize the "t" coordinate
- zmap/zline.c (next_closest): it's okay to go "back", since we may have
  multiple boundaries at the same place
- zmap/zline.c (zline): didn't initialize tmp_t
- zmap: added lots of debugging output



Modified: developers/werner/cncmap/zmap/Makefile
===================================================================
--- developers/werner/cncmap/zmap/Makefile	2009-10-22 13:23:25 UTC (rev 5701)
+++ developers/werner/cncmap/zmap/Makefile	2009-10-22 16:33:34 UTC (rev 5702)
@@ -15,7 +15,7 @@
 
 OBJS=try.o zline.o zmap.o
 
-CFLAGS = -Wall -Wshadow
+CFLAGS = -g -Wall -Wshadow
 LDFLAGS = -lm
 
 $(MAIN):	$(OBJS)

Modified: developers/werner/cncmap/zmap/zline.c
===================================================================
--- developers/werner/cncmap/zmap/zline.c	2009-10-22 13:23:25 UTC (rev 5701)
+++ developers/werner/cncmap/zmap/zline.c	2009-10-22 16:33:34 UTC (rev 5702)
@@ -11,8 +11,10 @@
  */
 
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
+#include <math.h>
 
 #include "zmap.h"
 #include "zline.h"
@@ -38,10 +40,12 @@
     int ref, int start, int n, double *t)
 {
 	int i;
+	double b;
 	double x, y, dx, dy, pos;
 	double best_t = 1;
 	int best_point = -1;
 
+	b = hypot(xb-xa, yb-ya);
 	for (i = start; i != n; i++) {
 		/*
 		 * Eliminate points that can't possibly be any closer. This
@@ -60,17 +64,22 @@
 		 * triangle at (t0, d0) - (t1, d0) - (t1, d1), where (t0, d0)
 		 * is point "ref" and (t1, d1) is the middle between points "i"
 		 * and "ref".
+		 *
+		 * Since our "t" axis is scaled by 1/b, we need to renormalize
+		 * the result.
 		 */
 		x = (proj[i].t+proj[ref].t)/2;
 		y = (proj[i].d+proj[ref].d)/2;
 		dx = proj[i].t-proj[ref].t;
 		dy = proj[i].d-proj[ref].d;
-		pos = x+dy*y/dx;
+		pos = x+y*dy/dx/b/b;
 
-		/* don't go back */
-		if (pos <= *t)
-			continue;
-
+fprintf(stderr, "? (%g, %g) [%g %g] (%g, %g) [%g %g] @ %g\n",
+  map[ref].x, map[ref].y, proj[ref].t, proj[ref].d,
+  map[i].x, map[i].y, proj[i].t, proj[i].d, pos);
+#if 0
+fprintf(stderr, "  x %g y %g dx %g dy %g\n", x, y, dx, dy);
+#endif
 		if (pos < best_t) {
 			best_t = pos;
 			best_point = i;
@@ -123,11 +132,14 @@
 
 	t = 0;
 	n = map_n;
+fprintf(stderr, "n %d\n", map_n);
 	while (n >= 3) {
 		best_t = 1;
 		best_next = best_old = -1;
 		for (i = 0; i != 3; i++) {
+			tmp_t = t;
 			tmp_i = next_closest(xa, ya, xb, yb, i, 3, n, &tmp_t);
+fprintf(stderr, "%d: i = %d t = %g\n", i, tmp_i, tmp_t);
 			if (tmp_t < best_t) {
 				best_t = tmp_t;
 				best_next = tmp_i;

Modified: developers/werner/cncmap/zmap/zmap.c
===================================================================
--- developers/werner/cncmap/zmap/zmap.c	2009-10-22 13:23:25 UTC (rev 5701)
+++ developers/werner/cncmap/zmap/zmap.c	2009-10-22 16:33:34 UTC (rev 5702)
@@ -50,7 +50,7 @@
 static int comp(const void *_a, const void *_b)
 {
 	const struct xyz *a = _a;
-	const struct xyz *b = _a;
+	const struct xyz *b = _b;
 	double d_a, d_b;
 
 	d_a = hypot(a->x-g_x, a->y-g_y);
@@ -86,6 +86,8 @@
 		t = ((map[i].x-xa)*xb+(map[i].y-ya)*yb)/b/b;
 		p[i].t = t;
 		p[i].d = hypot(xa+xb*t-map[i].x, ya+yb*t-map[i].y);
+fprintf(stderr, "PROJ %g %g -> t %g d %g\n",
+  map[i].x, map[i].y, p[i].t, p[i].d);
 	}
 	return p;
 }
@@ -115,6 +117,8 @@
 	double xv, yv, zv, v;
 	double s, t;
 
+fprintf(stderr, "point (%g, %g) -> (%g, %g) (%g, %g) (%g, %g)\n",
+  x, y, a.x, a.y, b.x, b.y, c.x, c.y);
 	xp = x-a.x;
 	yp = y-a.y;
 




More information about the commitlog mailing list