34#ifndef LIB2GEOM_SEEN_LINE_H
35#define LIB2GEOM_SEEN_LINE_H
52 : boost::equality_comparable< Line >
88 Line(
double a,
double b,
double c) {
120 return new Line(*
this);
139 double a = std::atan2(d[
Y], d[
X]);
140 if (a < 0) a += M_PI;
141 if (a == M_PI) a = 0;
288 std::optional<LineSegment>
clip(
Rect const &r)
const;
334 Coord x2 = v[
X]*v[
X], y2 = v[
Y]*v[
Y], xy = v[
X]*v[
Y];
353 std::swap(v[
X], v[
Y]);
370 std::vector<ShapeIntersection>
intersect(
Line const &other)
const;
371 std::vector<ShapeIntersection>
intersect(
Ray const &r)
const;
374 template <
typename T>
388 template <
typename T>
415 return ::Geom::distance(line.
pointAt(t), p);
459 if (angle < 0) angle += M_PI;
460 if (angle == M_PI) angle = 0;
508 return Line(O, bisect);
Defines the different types of exceptions that 2geom can throw.
Various trigoniometric helper functions.
3x3 matrix representing an affine transformation.
Directed angular interval.
Angle angleAt(Coord t) const
Get an angle corresponding to the specified time value.
Wrapper for angular values.
Coord nearestTime(Point const &p, Coord from=0, Coord to=1) const override
Compute a time value at which the curve comes closest to a specified point.
Point finalPoint() const override
Retrieve the end of the curve.
Point pointAt(Coord t) const override
Evaluate the curve at a specified time value.
Point initialPoint() const override
Retrieve the start of the curve.
Abstract continuous curve on a plane defined on [0,1].
Infinite line on a plane.
bool are_same(Line const &l1, Line const &l2, double eps=EPSILON)
Test whether two lines are approximately the same.
Line(double a, double b, double c)
Create a line based on the coefficients of its equation.
void setCoefficients(double a, double b, double c)
Set the coefficients of the line equation.
std::vector< double > coefficients() const
Get the coefficients of the line equation as a vector.
Coord timeAt(Point const &p) const
Get a time value corresponding to a point.
Affine rotationToZero(Dim2 d) const
Compute an affine which transforms all points on the line to zero X or Y coordinate.
Affine reflection() const
Compute an affine matrix representing a reflection about the line.
Line(Point const &a, Point const &b)
Create a line going through two points.
Line transformed(Affine const &m) const
Create a line transformed by an affine transformation.
void setAngle(Coord angle)
Set the angle the line makes with the X axis.
void setOrigin(Point const &p)
Set the point at zero time.
bool isDegenerate() const
Check if the line has more than one point.
Point origin() const
Get the line's origin point.
Line derivative() const
Create a derivative of the line.
void setPoints(Point const &a, Point const &b)
Set a line based on two points it should pass through.
Line(LineSegment const &seg)
Create a line by extending a line segment.
Point vector() const
Get the line's raw direction vector.
Affine rotationToAxis(Dim2 d) const
Compute a rotation affine which transforms the line to one of the axes.
Line(Point const &origin, Coord angle)
Create a line with the specified inclination.
void normalize()
Reparametrize the line so that it has unit speed.
friend Line operator*(Line const &l, T const &tr)
void setVector(Point const &v)
Set the speed of the line.
Line reversed() const
Create a line containing the same points, but in opposite direction.
Line normalized() const
Return a new line reparametrized for unit speed.
std::vector< Coord > roots(Coord v, Dim2 d) const
Find intersection with an axis-aligned line.
std::optional< LineSegment > clip(Rect const &r) const
Return the portion of the line that is inside the given rectangle.
bool isVertical() const
Check if the line is vertical (x is constant).
Affine transformTo(Line const &other) const
Create a transformation that maps one line to another.
Coord timeAtProjection(Point const &p) const
Get a time value corresponding to a projection of a point on the line.
Ray ray(Coord t)
Create a ray starting at the specified time value.
Point normalAndDist(double &dist) const
Line & operator*=(T const &tr)
bool are_orthogonal(Line const &l1, Line const &l2, double eps=EPSILON)
Test whether two lines are perpendicular.
Coord valueAt(Coord t, Dim2 d) const
Curve * portion(Coord f, Coord t) const
Same as segment(), but allocate the line segment dynamically.
static Line from_normal_distance(Point const &n, Coord c)
Create a line normal to a vector at a specified distance from origin.
static Line from_origin_and_vector(Point const &o, Point const &v)
Create a line from origin and unit vector.
Coord nearestTime(Point const &p) const
Find a point on the line closest to the query point.
Point initialPoint() const
Line(Ray const &r)
Create a line by extending a ray.
std::vector< ShapeIntersection > intersect(Line const &other) const
bool operator==(Line const &other) const
Coord angle() const
Angle the line makes with the X axis, in mathematical convention.
Point pointAt(Coord t) const
Point versor() const
Get the line's normalized direction vector.
Point normal() const
Get a unit vector normal to the line.
double distance(Point const &p, Line const &line)
Compute distance from point to line.
Line()
Create a default horizontal line.
LineSegment segment(Coord f, Coord t) const
Create a segment of this line.
bool isHorizontal() const
Check if the line is horizontal (y is constant).
Two-dimensional point that doubles as a vector.
constexpr Point cw() const
Return a point like this point but rotated +90 degrees.
Straight ray from a specific point to infinity.
void setOrigin(Point const &o)
Axis aligned, non-empty rectangle.
Rotation around the origin.
Structure representing the intersection of two curves.
BezierCurveN< 1 > LineSegment
Line segment.
constexpr Coord lerp(Coord t, Coord a, Coord b)
Numerically stable linear interpolation.
Dim2
2D axis enumeration (X or Y).
constexpr Dim2 other_dimension(Dim2 d)
Get the other (perpendicular) dimension.
double Coord
Floating point type used to store coordinates.
constexpr Coord EPSILON
Default "acceptably small" value.
OptCrossing intersection_impl(Ray const &r1, Line const &l2, unsigned int i)
Various utility functions.
void sincos(double angle, double &sin_, double &cos_)
Simultaneously compute a sine and a cosine of the same angle.
void filter_ray_intersections(std::vector< ShapeIntersection > &xs, bool a=false, bool b=true)
Point projection(Point const &p, Line const &line)
Line make_parallel_line(Point const &p, Line const &line)
Angle distance(Angle const &a, Angle const &b)
std::optional< Crossing > OptCrossing
OptCrossing intersection(Ray const &r1, Line const &l2)
Line make_bisector_line(LineSegment const &_segment)
double angle_between(Line const &l1, Line const &l2)
void filter_line_segment_intersections(std::vector< ShapeIntersection > &xs, bool a=false, bool b=true)
Removes intersections outside of the unit interval.
Line make_orthogonal_line(Point const &p, Line const &line)
bool clip(std::vector< RatQuad > &rq, const xAx &cs, const Rect &R)
Piecewise< SBasis > cross(Piecewise< D2< SBasis > > const &a, Piecewise< D2< SBasis > > const &b)
bool are_parallel(Line const &l1, Line const &l2, double eps=EPSILON)
Line make_angle_bisector_line(Point const &A, Point const &O, Point const &B)
T dot(D2< T > const &a, D2< T > const &b)
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
D2< T > rot90(D2< T > const &a)
Point middle_point(LineSegment const &_segment)