92 |
Vector operator-(const Vector<T>&v) const { return Vector(x-v.x, y-v.y); } |
Vector operator-(const Vector<T>&v) const { return Vector(x-v.x, y-v.y); } |
93 |
/** Return a vector like this, but rotated 90 degrees clockwise. |
/** Return a vector like this, but rotated 90 degrees clockwise. |
94 |
*/ |
*/ |
95 |
Vector cw90() { return Vector(y, -x); } |
Vector cw90() const { return Vector(y, -x); } |
96 |
/** Return the length of this vector. |
/** Return the length of this vector. |
97 |
*/ |
*/ |
98 |
double length() { return hypot(x, y); } |
double length() const { return hypot(x, y); } |
99 |
|
|
100 |
/** Dot this vector with another. |
/** Dot this vector with another. |
101 |
*/ |
*/ |
102 |
double dot(const Vector<T> &v) const { return x * v.x + y * v.y; } |
double dot(const Vector<T> &v) const { return x * v.x + y * v.y; } |
103 |
|
|
104 |
|
/** Cross this 2D vector with another - |
105 |
|
* gives the sine of the angle between the two, |
106 |
|
* multiplied by the lengths. |
107 |
|
* Useful for telling which side of a given vector you are. |
108 |
|
*/ |
109 |
|
double cross(const Vector<T> &v) const { |
110 |
|
return x * v.y - y * v.x; |
111 |
|
} |
112 |
|
|
113 |
|
double atan() const { |
114 |
|
return atan2(x, y); |
115 |
|
} |
116 |
}; |
}; |
117 |
|
|
118 |
/** Multiply vector by scalar. |
/** Multiply vector by scalar. |
314 |
HPoint2() {} |
HPoint2() {} |
315 |
HPoint2(T x, T y, T w) : x(x), y(y), w(w) { } |
HPoint2(T x, T y, T w) : x(x), y(y), w(w) { } |
316 |
HPoint2(ZPt p) : x(p.x), y(p.y), w(1) { } |
HPoint2(ZPt p) : x(p.x), y(p.y), w(1) { } |
317 |
|
HPoint2(Pt p) : x(p.x), y(p.y), w(1) { } |
318 |
|
|
319 |
HLine2<T> line(HPoint2 p) { |
HLine2<T> line(HPoint2 p) { |
320 |
T a, b, c; |
T a, b, c; |
368 |
|
|
369 |
template<class T> T dot(Vector<T> a, Vector<T> b) { return a.dot(b); } |
template<class T> T dot(Vector<T> a, Vector<T> b) { return a.dot(b); } |
370 |
|
|
371 |
|
|
372 |
|
/** Give the direction vector for a given angle: |
373 |
|
* (sin angle, cos angle). |
374 |
|
*/ |
375 |
|
inline Vec dirVec(float angle) { |
376 |
|
return Vec(sin(angle), cos(angle)); |
377 |
|
} |
378 |
} |
} |
379 |
|
|
380 |
// Export some to Vob |
// Export some to Vob |
384 |
using Vec23::Pt; |
using Vec23::Pt; |
385 |
using Vec23::Vec; |
using Vec23::Vec; |
386 |
using Vec23::lerp; |
using Vec23::lerp; |
387 |
|
using Vec23::dirVec; |
388 |
} |
} |
389 |
#endif |
#endif |