diff options
-rw-r--r-- | board.c | 12 | ||||
-rw-r--r-- | board.h | 3 | ||||
-rw-r--r-- | comp.c | 16 | ||||
-rw-r--r-- | comp.h | 2 |
4 files changed, 17 insertions, 16 deletions
@@ -52,6 +52,18 @@ void init_board() init_rings(); } +struct ccoords pol_to_cart(struct pcoords c) +{ + double t = c.a * (M_PI / 180); + return (struct ccoords){ .x = c.r * cos(t), .y = c.r * sin(t) }; +} + +struct pcoords cart_to_pol(struct ccoords c) +{ + return (struct pcoords){ .a = atan2(c.y, c.x) * (180 / M_PI), + .r = sqrt(pow(c.x, 2) + pow(c.y, 2)) }; +} + static int sector_from_angle(double angle) { double shifted = angle - 90 - (SECTOR_WIDTH / 2); @@ -60,6 +60,9 @@ struct pcoords { void init_board(); +struct ccoords pol_to_cart(struct pcoords c); +struct pcoords cart_to_pol(struct ccoords c); + struct segment segment_from_pcoords(struct pcoords c); struct segment segment_from_name(const char *name); struct pcoords segment_centre(struct segment seg); @@ -70,28 +70,16 @@ static double gauss(double mean, double stdev) return mean + (curr * stdev); } -static struct ccoords get_offset() +static struct ccoords gauss_offset() { return (struct ccoords){ .x = gauss(0, horizontal_stdev), .y = gauss(0, vertical_stdev) }; } -struct ccoords pol_to_cart(struct pcoords c) -{ - double t = c.a * (M_PI / 180); - return (struct ccoords){ .x = c.r * cos(t), .y = c.r * sin(t) }; -} - -static struct pcoords cart_to_pol(struct ccoords c) -{ - return (struct pcoords){ .a = atan2(c.y, c.x) * (180 / M_PI), - .r = sqrt(pow(c.x, 2) + pow(c.y, 2)) }; -} - static struct pcoords throw_dart(struct pcoords target, struct ccoords *cc) { struct ccoords tc = pol_to_cart(target); - struct ccoords offset = get_offset(); + struct ccoords offset = gauss_offset(); cc->x = tc.x + offset.x; cc->y = tc.y + offset.y; @@ -5,8 +5,6 @@ extern double horizontal_stdev, vertical_stdev; -struct ccoords pol_to_cart(struct pcoords c); - void comp_set_difficulty(int diff); void comp_visit(struct leg *l); |