Saga3D API Documentation
1.0-RC4
|
Go to the documentation of this file.
5 #ifndef __IRR_LINE_2D_H_INCLUDED__
6 #define __IRR_LINE_2D_H_INCLUDED__
44 void setLine(
const T& xa,
const T& ya,
const T& xb,
const T& yb){
start.set(xa, ya);
end.set(xb, yb);}
46 void setLine(
const vector2d<T>& nstart,
const vector2d<T>& nend){
start.set(nstart);
end.set(nend);}
79 std::int32_t o2 =
start.checkOrientation(
end, other.
end);
80 std::int32_t o3 = other.
start.checkOrientation(other.
end,
start);
81 std::int32_t o4 = other.
start.checkOrientation(other.
end,
end);
84 if (o1 != o2 && o3 != o4)
110 return a.nearlyParallel(b, factor);
119 const float commonDenominator = (float)((l.
end.Y - l.
start.Y)*(
end.X -
start.X) -
122 if (commonDenominator != 0.f)
127 const float uA = numeratorA / commonDenominator;
159 bool intersectWith(
const line2d<T>& l, vector2d<T>& out,
bool checkOnlySegments=
true,
bool ignoreCoincidentLines=
false)
const
163 const float commonDenominator = (float)((l.
end.Y - l.
start.Y)*(
end.X -
start.X) -
172 if(
equals(commonDenominator, 0.f))
176 if(!ignoreCoincidentLines &&
equals(numeratorA, 0.f) &&
equals(numeratorB, 0.f))
218 out = core::vector2d<T>();
221 if (
end != maxp &&
end != minp)
225 if (l.
end != maxp && l.
end != minp)
227 out.X = (T)(out.X/2);
228 out.Y = (T)(out.Y/2);
239 const float uA = numeratorA / commonDenominator;
240 if (checkOnlySegments)
242 if(uA < 0.f || uA > 1.f)
245 const float uB = numeratorB / commonDenominator;
246 if(uB < 0.f || uB > 1.f)
271 return vect.getAngleWith(vect2);
301 vector2d<T>
getClosestPoint(
const vector2d<T>& point,
bool checkOnlySegments=
true)
const
303 vector2d<double> c((
double)(point.X-
start.X), (
double)(point.Y-
start.Y));
305 double d = v.getLength();
309 double t = v.dotProduct(c);
311 if (checkOnlySegments)
313 if (t < 0)
return vector2d<T>((T)
start.X, (T)
start.Y);
314 if (t > d)
return vector2d<T>((T)
end.X, (T)
end.Y);
318 return vector2d<T>((T)(
start.X + v.X), (T)(
start.Y + v.Y));
331 vector2df c = point - start;
332 vector2df v = end - start;
333 float d = (float)v.getLength();
337 float t = v.dotProduct(c);
339 if (checkOnlySegments)
341 if (t < 0)
return start;
342 if (t > d)
return end;
line2d< T > operator-(const vector2d< T > &point) const
bool intersectAsSegments(const line2d< T > &other) const
bool operator==(const line2d< T > &other) const
bool operator!=(const line2d< T > &other) const
vector2d< T > fastLinesIntersection(const line2d< T > &l) const
bool incidentSegments(const line2d< T > &other) const
line2d()
Default constructor for line going from (0,0) to (1,1).
bool lineIntersectSegment(const line2d< T > &segment, vector2d< T > &out) const
void setLine(const T &xa, const T &ya, const T &xb, const T &yb)
Set this line to new line going through the two points.
vector2d< T > getUnitVector() const
Get unit vector of the line.
vector2d< T > getVector() const
Get the vector of the line.
T getLengthSQ() const
Get squared length of the line.
line2d< T > & operator-=(const vector2d< T > &point)
bool isPointBetweenStartAndEnd(const vector2d< T > &point) const
Check if the given point is between start and end of the line.
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
line2d< float > line2df
Typedef for an float line.
bool nearlyParallel(const line2d< T > &line, const T factor=relativeErrorFactor< T >()) const
bool isBetweenPoints(const glm::vec3 &point, const glm::vec3 &begin, const glm::vec3 &end)
bool isPointOnLine(const vector2d< T > &point) const
Check if the given point is a member of the line.
bool intersectWith(const line2d< T > &l, vector2d< T > &out, bool checkOnlySegments=true, bool ignoreCoincidentLines=false) const
Tests if this line intersects with another line.
T getLength() const
Get length of line.
vector2d< T > getClosestPoint(const vector2d< T > &point, bool checkOnlySegments=true) const
Get the closest point on this line to a point.
line2d(T xa, T ya, T xb, T yb)
Constructor for line between the two points.
T getPointOrientation(const vector2d< T > &point) const
Tells us if the given point lies to the left, right, or on the line.
line2d(const line2d< T > &other)
Copy constructor.
line2d(const vector2d< T > &start, const vector2d< T > &end)
Constructor for line between the two points given as vectors.
void setLine(const line2d< T > &line)
Set this line to new line given as parameter.
void setLine(const vector2d< T > &nstart, const vector2d< T > &nend)
Set this line to new line going through the two points.
vector2d< T > start
Start point of the line.
line2d< T > operator+(const vector2d< T > &point) const
2D line between two points with intersection methods.
line2d< std::int32_t > line2di
Typedef for an integer line.
double getAngleWith(const line2d< T > &l) const
Get angle between this line and given line.
line2d< T > & operator+=(const vector2d< T > &point)
vector2d< T > end
End point of the line.
vector2d< T > getMiddle() const
Get middle of the line.