summaryrefslogtreecommitdiff
path: root/board.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-26 12:31:32 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-26 12:31:32 -0700
commit51447980c54eab163773b80211a73dbfb3636e79 (patch)
treeb6d3ab39a382dcda4652c8475c1c66a7b977e2e1 /board.c
parent345f3e9e54381712a86a699d8968dc0f7c8565e9 (diff)
downloaddartboat-51447980c54eab163773b80211a73dbfb3636e79.tar.gz
dartboat-51447980c54eab163773b80211a73dbfb3636e79.tar.xz
move coord conversion to board code
Diffstat (limited to 'board.c')
-rw-r--r--board.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/board.c b/board.c
index 7aceed6..94dd764 100644
--- a/board.c
+++ b/board.c
@@ -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);