27#ifndef EASY3D_CORE_LINE_H
28#define EASY3D_CORE_LINE_H
30#include <easy3d/core/vec.h>
39 template <
int DIM,
typename FT>
79 bool feet(
const thisclass& other, Point& p1, Point& p2)
const;
90 template <
int DIM,
typename FT>
inline
93 LOG_IF(
length(dir_) < 1e-15, ERROR)
94 <<
"degenerate line constructed from point (" << p <<
") and direction (" << dir <<
")";
98 template <
int DIM,
typename FT>
inline
102 FT b =
dot(dir_, dir_);
104 if (std::abs(a * a - b * c) < epsilon<FT>())
106 FT d =
dot(other.
point() - p_, dir_);
115 t1 = (a * e - c * d) / (a * a - b * c);
116 t2 = b / a * t1 - d / a;
125 template <
int DIM,
typename FT>
inline
132 template <
int DIM,
typename FT>
inline
A generic line representation, which supports both 2D and 3D lines.
Definition: line.h:40
GenericLine()=default
Default constructor.
FT squared_distance(const Point &p) const
Returns the squared distance of a point p to this line.
Definition: line.h:71
static GenericLine from_two_points(const Point &p, const Point &q)
Constructs a line from two points p and q.
Definition: line.h:50
void set(const Point &p, const Vector &dir)
Sets a line from a point p and its direction dir.
Definition: line.h:56
Point projection(const Point &p) const
Returns the projection of a point p on this line.
Definition: line.h:68
const Vector & direction() const
Returns the direction of a line.
Definition: line.h:62
const Point & point() const
Returns an arbitrary point on a line.
Definition: line.h:65
static GenericLine from_point_and_direction(const Point &p, const Vector &dir)
Constructs a line from a point p and its direction dir.
Definition: line.h:48
bool feet(const thisclass &other, Point &p1, Point &p2) const
Computes the perpendicular feet with another line.
Definition: line.h:99
Definition: collider.cpp:182
std::istream & operator>>(std::istream &is, GenericLine< DIM, FT > &line)
Definition: line.h:133
T length(const Vec< N, T > &v)
Computes the length/magnitude of a vector.
Definition: vec.h:289
std::ostream & operator<<(std::ostream &os, Graph::Vertex v)
Definition: graph.h:920
FT dot(const std::vector< FT > &, const std::vector< FT > &)
Inner product for vectors.
Definition: matrix.h:1803
Vec< N, T > normalize(const Vec< N, T > &v)
Computes and returns the normalized vector (Note: the input vector is not modified).
Definition: vec.h:299
T length2(const Vec< N, T > &v)
Computes the squared length/magnitude of a vector.
Definition: vec.h:293