From 76b1b3e42e5c0df7e90db7e75027d6793d90c578 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 19 Mar 2012 01:17:14 -0300 Subject: [PATCH] gp2rml: improved distance calculation; corrected compiler invocation --- gp2rml/Makefile | 2 +- gp2rml/gp2rml.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gp2rml/Makefile b/gp2rml/Makefile index c7d5b77..d7d38cb 100644 --- a/gp2rml/Makefile +++ b/gp2rml/Makefile @@ -16,7 +16,7 @@ MAIN=gp2rml OBJS=gp2rml.o CFLAGS = -g -Wall -Wshadow -LDFLAGS = -lm +LDLIBS = -lm $(MAIN): $(OBJS) # $(CC) $(LDFLAGS) -o $(MAIN) $(OBJS) diff --git a/gp2rml/gp2rml.c b/gp2rml/gp2rml.c index 47f597b..8297b6a 100644 --- a/gp2rml/gp2rml.c +++ b/gp2rml/gp2rml.c @@ -1,8 +1,8 @@ /* * gp2rml.c - Convert from gnuplot to RML * - * Written 2010-2011 by Werner Almesberger - * Copyright 2010-2011 Werner Almesberger + * Written 2010-2012 by Werner Almesberger + * Copyright 2010-2012 Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -131,6 +131,7 @@ static void output_paths(double z_clear, double xy_speed, double z_speed) const struct segment *seg; double x = 0, y = 0, z = 0; double d, s = 0, t = 0; + double txy, tz; printf("IN;!MC1;PA\n"); printf("!ZO%d;!PZ0,%d;PU\n", units(z_max), units(z_clear)); @@ -153,9 +154,12 @@ static void output_paths(double z_clear, double xy_speed, double z_speed) while (seg) { printf("!ZZ%d,%d,%d\n", units(seg->x), units(seg->y), units(seg->z-z_max)); - d = hypot(hypot(x-seg->x, y-seg->y), z-seg->z); + d = hypot(x-seg->x, y-seg->y); + txy = d/xy_speed; + tz = fabs(z-seg->z)/z_speed; + t += txy > tz ? txy : tz; + d = hypot(d, z-seg->z); s += d; - t += d/z_speed; x = seg->x; y = seg->y; z = seg->z;