1#ifndef BITSIM_GEOMETRY_GENERIC_LINE_H
2#define BITSIM_GEOMETRY_GENERIC_LINE_H
109 : id_(id), start_(p1), end_(p2)
132 throw std::logic_error(
"Invalid vertex index. Index not in [0,1]");
147 throw std::logic_error(
"Invalid vertex index. Index not in [0,1]");
152 return (end_[1] - start_[1]) / (end_[0] - start_[0]);
157 auto slope_ =
slope();
158 return start_[1] - slope_ * start_[0];
166 const real_t dx = end_[0] - start_[0];
167 const real_t dy = end_[1] - start_[1];
171 return std::hypot(n[0] - start_[0], n[1] - start_[1]);
173 return std::fabs(dx * (n[1] - start_[1]) - dy * (n[0] - start_[0])) /
length;
180 const real_t dx = end_[0] - start_[0];
181 const real_t dy = end_[1] - start_[1];
182 const real_t length2 = dx * dx + dy * dy;
186 : std::clamp(((n[0] - start_[0]) * dx + (n[1] - start_[1]) * dy) / length2, 0.0, 1.0);
187 return std::hypot(n[0] - (start_[0] + t * dx), n[1] - (start_[1] + t * dy));
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
bool has_valid_id() const noexcept
Returns true iff id_ != rlenvscpp::consts::INVALID_ID.
Definition generic_line.h:58
real_t slope() const
The slope of the line; infinite for a vertical line.
Definition generic_line.h:150
GenericLine()
Constructor.
Definition generic_line.h:103
uint_t get_id() const noexcept
Returns the id of the line.
Definition generic_line.h:63
real_t segment_distance(const vertex_type &n) const
The distance of the point from the segment between the two vertices.
void set_id(uint_t id) noexcept
Set the id of the line.
Definition generic_line.h:68
const vertex_type & get_vertex(uint_t v) const
Returns the v-th vertex of the segment.
Definition generic_line.h:120
real_t factor() const
Returns the constant factor.
Definition generic_line.h:155
real_t distance(const vertex_type &n) const
The perpendicular distance of the point from the infinite line through the two vertices; the distance...
static const int dimension
Definition generic_line.h:26
real_t length() const
Calculate the length of the line.
Definition generic_line.h:94
GeomPoint< dim > vertex_type
Definition generic_line.h:28
A class that describes a point with spacedim spatial dimension space.
Definition geom_point.h:22
Definition bitsim_consts.cpp:10
const uint_t INVALID_ID
Invalid id.
Definition bitsim_consts.h:16
Definition generic_line.h:16
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20