21 cxy(
double X,
double Y)
46 return v.x * v.x + v.y * v.y;
53 const cxy &end2)
const
57 double lAB = AB.x * AB.x + AB.y * AB.y;
58 return (AB.x * AP.x + AB.y * AP.y) / lAB;
64 const cxy &end2)
const
72 cxy ret(end1.x + t * (end2.x - end1.x),
73 end1.y + t * (end2.y - end1.y));
83 const cxy &end2)
const
85 double t = tclosest(end1, end2);
94 return dist2(closest);
98 bool isInside(
const std::vector<cxy> &polygon)
const
101 std::vector<cxy>::const_iterator j = polygon.end() - 1;
102 for (std::vector<cxy>::const_iterator i = polygon.begin();
103 i != polygon.end(); j = i++)
105 if (((i->y > y) != (j->y > y)) &&
106 (x < (j->x - i->x) * (y - i->y) / (j->y - i->y) + i->x))
112 static cxy enclosingWidthHeight(
const std::vector<cxy> &polygon)
115 for (
const cxy &p : polygon)
127 ret.x = max.x - min.x;
128 ret.y = max.y - min.y;
140 const cxy &a,
const cxy &b,
141 const cxy &c,
const cxy &d)
154 double A1 = b.y - a.y;
155 double B1 = a.x - b.x;
156 double C1 = A1 * a.x + B1 * a.y;
157 double A2 = d.y - c.y;
158 double B2 = c.x - d.x;
159 double C2 = A2 * c.x + B2 * c.y;
173 double det = A1 * B2 - A2 * B1;
174 if (fabs(det) < 0.0001)
179 p.x = (B2 * C1 - B1 * C2) / det;
180 p.y = (A1 * C2 - A2 * C1) / det;
183 if (!(std::min(a.x, b.x) <= p.x && p.x <= std::max(a.x, b.x)))
185 if (!(std::min(a.y, b.y) <= p.y && p.y <= std::max(a.y, b.y)))
187 if (!(std::min(c.x, d.x) <= p.x && p.x <= std::max(c.x, d.x)))
189 if (!(std::min(c.y, d.y) <= p.y && p.y <= std::max(c.y, d.y)))
196 static bool isIntersect(
cxy &p1,
cxy &q1,
cxy &p2,
cxy &q2);
204 const cxy &a,
const cxy &b,
205 const cxy &c,
const cxy &d)
209 double dot = v1.x * v2.x + v1.y * v2.y;
210 double det = v1.x * v2.y - v1.y * v2.x;
211 return atan2(det, dot);
236 return ((x > -DBL_MAX + 1) && (y > -DBL_MAX + 1));
243 void zoom(
float ratio)
248 bool operator==(
const cxy &other)
const
250 return x == other.x && y == other.y;
252 cxy operator+(
const cxy &other)
const
259 cxy operator-(
const cxy &other)
const
266 cxy &operator*=(
float s)
272 cxy &operator*=(
const cxy &other)
278 cxy &operator+=(
const cxy &other)
284 cxy &operator/=(
float s)
290 friend std::ostream &operator<<(std::ostream &os,
cxy p)
292 os <<
"(" << p.x <<
"," << p.y <<
")";
308 cxyz(
double X,
double Y,
double Z)
332 p0.x + p01.x + p02.x,
333 p0.y + p01.y + p02.y,
334 p0.z + p01.z + p02.z);
340 y * other.z - z * other.y,
341 z * other.x - x * other.z,
342 x * other.y - y * other.z);
345 double dot(
const cxyz &other)
366 cxyz lap0(la.x - p0.x, la.y - p0.y, la.z - p0.x);
367 double divisor = lb.
vect(la).dot(crossall);
368 double t = crossall.dot(lap0) / divisor;
369 double u = crossu.dot(lap0) / divisor;
370 double v = crossv.dot(lap0) / divisor;
373 if (t >= 0 && t <= 1)
374 if (u >= 0 && u <= 1)
375 if (v >= 0 && v <= 1)
379 la.x + t * (lb.x - la.x),
380 la.y + t * (lb.y - la.y),
381 la.z + t * (lb.z - la.z));
385 bool operator==(
const cxyz &other)
const
387 return x == other.x && y == other.y && z == other.z;
2D point or vector
Definition: cxy.h:10
static double clockwise(const cxy &a, const cxy &b, const cxy &c)
clockwise turn going from a to b to c, radians
Definition: cxy.h:220
static bool isIntersection(cxy &p, const cxy &a, const cxy &b, const cxy &c, const cxy &d)
true if line segments intersect
Definition: cxy.h:138
static double angle(const cxy &a, const cxy &b, const cxy &c, const cxy &d)
angle between line segments, radians
Definition: cxy.h:203
double dist2(const cxy &other) const
distance squared from this point to other
Definition: cxy.h:43
cxy vect(const cxy &other) const
vector from this point to other
Definition: cxy.h:32
double dis2toline(const cxy &end1, const cxy &end2) const
distance squared from this point to nearest point on line segment
Definition: cxy.h:81
bool isInside(const std::vector< cxy > &polygon) const
true if point inside polygon
Definition: cxy.h:98
3D point or vector
Definition: cxy.h:298
cxyz vect(const cxyz &other) const
vector from this point to other
Definition: cxy.h:316
static cxyz intersectLineTriangle(const cxyz &la, const cxyz &lb, const cxyz &p0, const cxyz &p1, const cxyz &p2)
intersection point between line and triangle
Definition: cxy.h:359