API functions that utilize the vec2d class are grouped here. For details of the class, including member functions, see vec2d. vec2d is used for the two dimensional problems that come up inside three dimensional ones – parameter space coordinates, projections into a plane, and polygon tests. Click here to return to the main page. More...
Classes | |
| class | vec2d |
Functions | |
| vec2d::vec2d (double xx, double yy) | |
| double & | vec2d::operator[] (int i) |
| vec2d & | vec2d::set_xy (double xx, double yy) |
| vec2d & | vec2d::set_x (double xx) |
| vec2d & | vec2d::set_y (double yy) |
| double | vec2d::x () const |
| double | vec2d::y () const |
| double | vec2d::mag () const |
| void | vec2d::normalize () |
Friends | |
| vec2d | vec2d::operator+ (const vec2d &a, const vec2d &b) |
| vec2d | vec2d::operator- (const vec2d &a, const vec2d &b) |
| vec2d | vec2d::operator* (const vec2d &a, double b) |
| vec2d | vec2d::operator* (const vec2d &a, const vec2d &b) |
| vec2d | vec2d::operator/ (const vec2d &a, double b) |
| double | vec2d::dist (const vec2d &a, const vec2d &b) |
| double | vec2d::dist_squared (const vec2d &a, const vec2d &b) |
| double | vec2d::cross (const vec2d &a, const vec2d &b) |
| double | vec2d::dot (const vec2d &a, const vec2d &b) |
| double | vec2d::angle (const vec2d &a, const vec2d &b) |
| double | vec2d::cos_angle (const vec2d &a, const vec2d &b) |
| int | vec2d::seg_seg_intersect (const vec2d &pnt_A, const vec2d &pnt_B, const vec2d &pnt_C, const vec2d &pnt_D, vec2d &int_pnt, double &t1, double &t2) |
| vec2d | vec2d::proj_pnt_on_line_seg (const vec2d &line_A, const vec2d &line_B, const vec2d &pnt) |
| double | vec2d::proj_pnt_on_line_u (const vec2d &line_A, const vec2d &line_B, const vec2d &pnt) |
| bool | vec2d::PointInPolygon (const vec2d &R, const std::vector< vec2d > &pnts) |
| double | vec2d::det (const vec2d &p0, const vec2d &p1, const vec2d &offset) |
| double | vec2d::poly_area (const std::vector< vec2d > &pnt_vec) |
| vec2d | vec2d::poly_centroid (const std::vector< vec2d > &pnt_vec) |
| double | vec2d::orient2d (const vec2d &p0, const vec2d &p1, const vec2d &p) |
| void | vec2d::bi_lin_interp (const vec2d &p0, const vec2d &p1, const vec2d &p2, vec2d const &p3, double s, double t, vec2d &p_out) |
| int | vec2d::inverse_bi_lin_interp (const vec2d &p0, const vec2d &p1, const vec2d &p2, vec2d const &p3, const vec2d &p, double &s, double &t, double &s2, double &t2) |
| class vec2d |
vec2d is typically used to describe coordinate points and vectors in 2D space. Both elements in the vector are of type double.
Public Member Functions | |
|---|---|
| vec2d (double xx, double yy) | |
| vec2d & | operator= (double a) |
| double & | operator[] (int i) |
| const double & | operator[] (int i) const |
| vec2d & | set_xy (double xx, double yy) |
| vec2d & | set_x (double xx) |
| vec2d & | set_y (double yy) |
| double | x () const |
| double | y () const |
| double * | data () |
| vec2d | transform (float mat[3][3]) |
| vec2d | transform (double mat[3][3]) |
| vec2d & | operator+= (const vec2d &b) |
| vec2d & | operator-= (const vec2d &b) |
| vec2d & | operator*= (double b) |
| double | mag () const |
| void | normalize () |
Public Attributes | |
| double | v [2] |
Friends | |
| vec2d | operator+ (const vec2d &a, const vec2d &b) |
| vec2d | operator- (const vec2d &a, const vec2d &b) |
| vec2d | operator* (const vec2d &a, double b) |
| vec2d | operator* (double b, const vec2d &a) |
| vec2d | operator* (const vec2d &a, const vec2d &b) |
| vec2d | operator/ (const vec2d &a, double b) |
| double | dist (const vec2d &a, const vec2d &b) |
| double | dist_squared (const vec2d &a, const vec2d &b) |
| double | cross (const vec2d &a, const vec2d &b) |
| double | dot (const vec2d &a, const vec2d &b) |
| double | angle (const vec2d &a, const vec2d &b) |
| double | cos_angle (const vec2d &a, const vec2d &b) |
| int | seg_seg_intersect (const vec2d &pnt_A, const vec2d &pnt_B, const vec2d &pnt_C, const vec2d &pnt_D, vec2d &int_pnt, double &t1, double &t2) |
| vec2d | proj_pnt_on_line_seg (const vec2d &line_A, const vec2d &line_B, const vec2d &pnt) |
| double | proj_pnt_on_line_u (const vec2d &line_A, const vec2d &line_B, const vec2d &pnt) |
| void | encode (double x_min, double y_min, double x_max, double y_max, const vec2d &pnt, int code[4]) |
| void | clip_seg_rect (double x_min, double y_min, double x_max, double y_max, vec2d &pnt1, vec2d &pnt2, int &visible) |
| bool | PointInPolygon (const vec2d &R, const std::vector< vec2d > &pnts) |
| double | det (const vec2d &p0, const vec2d &p1, const vec2d &offset) |
| double | poly_area (const std::vector< vec2d > &pnt_vec) |
| vec2d | poly_centroid (const std::vector< vec2d > &pnt_vec) |
| double | orient2d (const vec2d &p0, const vec2d &p1, const vec2d &p) |
| void | bi_lin_interp (const vec2d &p0, const vec2d &p1, const vec2d &p2, vec2d const &p3, double s, double t, vec2d &p_out) |
| int | inverse_bi_lin_interp (const vec2d &p0, const vec2d &p1, const vec2d &p2, vec2d const &p3, const vec2d &p, double &s, double &t, double &s2, double &t2) |
| double vec2d::mag | ( | ) | const |
| void vec2d::normalize | ( | ) |
|
inline |
Index a vec2d by coordinate, 0 for X and 1 for Y. An index outside that range raises an IndexError, which is also what lets list() and tuple() walk a vec2d.
| [in] | i | int Coordinate index, 0 or 1 |
| vec2d & vec2d::set_x | ( | double | xx | ) |
Set the X coordinate (index 0) of the vec2d
| [in] | xx | double New X value |
| vec2d & vec2d::set_xy | ( | double | xx, |
| double | yy ) |
Set both coordinates of the vec2d
| [in] | xx | double New X value |
| [in] | yy | double New Y value |
| vec2d & vec2d::set_y | ( | double | yy | ) |
Set the Y coordinate (index 1) of the vec2d
| [in] | yy | double New Y value |
| vec2d::vec2d | ( | double | xx, |
| double | yy ) |
Construct a vec2d from its two coordinates. The default constructor leaves the coordinates uninitialized, so prefer this one unless the value is about to be overwritten.
| [in] | xx | double X coordinate |
| [in] | yy | double Y coordinate |
| double vec2d::x | ( | ) | const |
| double vec2d::y | ( | ) | const |
|
friend |
Interpolate a point inside the quadrilateral p0, p1, p2, p3. The parameter s runs from the p0-p3 edge to the p1-p2 edge and t runs from the p0-p1 edge to the p3-p2 edge, both over [0, 1].
Calculate the cosine of the angle between two vec2d. Cheaper than angle, which has to take an arc cosine, and enough on its own when the angle is only being compared.
Calculate the 2D cross product of two vec2d. In two dimensions the cross product is the single scalar a.x * b.y - a.y * b.x, which is the signed area of the parallelogram they span.
Twice the signed area of the triangle p0, p1, offset. Positive when the three points turn counter-clockwise, so the sign says which side of the line p0-p1 the third point is on.
Calculate the distance between two vec2d
|
friend |
Recover the parameters s and t that place a point inside the quadrilateral p0, p1, p2, p3 – the inverse of bi_lin_interp. The problem is quadratic, so it can have two answers, returned as (s, t) and (s2, t2); the return value says how many were found. A configuration that degenerates for the point being asked about can return none.
| [in] | p0 | vec2d First corner |
| [in] | p1 | vec2d Second corner |
| [in] | p2 | vec2d Third corner |
| [in] | p3 | vec2d Fourth corner |
| [in] | p | vec2d Point to locate |
| [out] | s | double First parameter of the first solution |
| [out] | t | double Second parameter of the first solution |
| [out] | s2 | double First parameter of the second solution |
| [out] | t2 | double Second parameter of the second solution |
Report which side of the directed line p0-p1 the point p falls on. Positive when p is to the left, negative to the right, and zero when the three are collinear.
| [in] | p0 | vec2d First point of the line |
| [in] | p1 | vec2d Second point of the line |
| [in] | p | vec2d Point to test |
Test whether a point lies inside a polygon. The polygon is given as its vertices in order; it does not have to be convex and does not have to repeat its first point at the end.
| [in] | R | vec2d Point to test |
| [in] | pnts | vector<vec2d> Vertices of the polygon, in order |
|
friend |
Calculate the area enclosed by a polygon, given as its vertices in order. The result is unsigned, so the winding direction does not matter. Repeating the first point at the end is allowed but not required.
| [in] | pnt_vec | vector<vec2d> Vertices of the polygon, in order |
Calculate the centroid of a polygon, given as its vertices in order. This is the centroid of the enclosed area, not the average of the vertices.
| [in] | pnt_vec | vector<vec2d> Vertices of the polygon, in order |
Project a point onto a line segment. The result is clamped to the segment, so a point that projects past either end comes back as that end point.
| [in] | line_A | vec2d First point of the segment |
| [in] | line_B | vec2d Second point of the segment |
| [in] | pnt | vec2d Point to project |
Project a point onto a line and return where along it the projection falls, running 0 at the first point to 1 at the second. Unlike proj_pnt_on_line_seg the result is not clamped, so a point beyond the segment gives a parameter outside [0, 1].
| [in] | line_A | vec2d First point of the line |
| [in] | line_B | vec2d Second point of the line |
| [in] | pnt | vec2d Point to project |
|
friend |
Intersect two line segments, AB and CD. Reports whether they cross, and where. The parameters t1 and t2 locate the intersection along each segment, running 0 at the first point to 1 at the second.
| [in] | pnt_A | vec2d First point of the first segment |
| [in] | pnt_B | vec2d Second point of the first segment |
| [in] | pnt_C | vec2d First point of the second segment |
| [in] | pnt_D | vec2d Second point of the second segment |
| [out] | int_pnt | vec2d Intersection point |
| [out] | t1 | double Parameter of the intersection along AB, in [0, 1] |
| [out] | t2 | double Parameter of the intersection along CD, in [0, 1] |