From 8151e2cde5d855b410431764bff9c0e01b93efa9 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 7 Jan 2015 14:38:45 +0100 Subject: Initial commit. --- geom.hpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 geom.hpp (limited to 'geom.hpp') diff --git a/geom.hpp b/geom.hpp new file mode 100644 index 0000000..056a36e --- /dev/null +++ b/geom.hpp @@ -0,0 +1,61 @@ +#pragma once + +#include + +struct vec { + double x, y; + + vec(double xx, double yy) : x(xx), y(yy) {} + + double norm() const { + return sqrt(x*x + y*y); + } + + double angle() const { + double xx = x / norm(); + double a = acos(x); + return (y > 0 ? a : -a); + } + + vec operator+ (const vec& o) const { + return vec(x + o.x, y + o.y); + } +}; + +struct line { + // Line defined by ax + by + c = 0 + double a, b, c; + + line(double aa, double bb, double cc) : a(aa), b(bb), c(cc) {} + + double dist(double x, double y) const { + // TODO + return 1; + } + + double angle() const { + return vec(-b, a).angle(); + } + +}; + +struct circle { + vec c; + double r; + + circle(double x, double y, double rr) : c(x, y), r(rr) {} + circle(vec cc, double rr) : c(cc), r(rr) {} +}; + +struct circpoint { + circle c; + double theta; + + circpoint(circle cc, double th) : c(cc), theta(th) {} + + vec pos() const { + return c.c + vec(c.r * cos(theta), c.r * sin(theta)); + } +}; + +/* vim: set ts=4 sw=4 tw=0 noet :*/ -- cgit v1.2.3