|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
2D vector with the usual linear algebra: dot product, determinant, projection, rotation, angles. More...
#include <MathClasses.h>
Public Member Functions | |
| Vector2D () | |
| Zero vector. | |
| Vector2D (double x, double y) | |
| From components. | |
| virtual | ~Vector2D () |
| double | operator[] (int n) const |
| Component access: 0=x, 1=y. | |
| bool | operator== (const Vector2D &v) const |
| Component equality. | |
| Vector2D | operator- (const Vector2D &v) const |
| Difference. | |
| Vector2D | operator+ (const Vector2D &v) const |
| Sum. | |
| double | operator* (const Vector2D &v) const |
| Dot product. | |
| Vector2D | operator- (double a) const |
| Subtract scalar from each component. | |
| Vector2D | operator+ (double a) const |
| Add scalar to each component. | |
| Vector2D | operator* (double a) const |
| Scale. | |
| const Vector2D & | operator-= (const Vector2D &v) |
| In-place subtract. | |
| const Vector2D & | operator+= (const Vector2D &v) |
| In-place add. | |
| const Vector2D & | operator-= (double a) |
| In-place scalar subtract. | |
| const Vector2D & | operator+= (double a) |
| In-place scalar add. | |
| const Vector2D & | operator*= (double a) |
| In-place scale. | |
| double | getX () const |
| double | getY () const |
| bool | set (const PointFloat &p1, const PointFloat &p2) |
| Set as p2-p1. | |
| bool | set (double x1, double y1, double x2, double y2) |
| Set as (x2-x1, y2-y1). | |
| bool | set (double x, double y) |
| Set components. | |
| bool | setX (double v) |
| Set x. | |
| bool | setY (double v) |
| Set y. | |
| bool | setLength (double l) |
Rescale to length l, keeping direction. | |
| bool | makeUnitVector () |
| Normalize in place. | |
| double | length () const |
| double | det (const Vector2D &v) const |
| 2D cross product / determinant (x*v.y - y*v.x); sign gives turn direction. | |
| bool | isOrthogonalWith (const Vector2D &v) const |
| bool | isParallelWith (const Vector2D &v) const |
| Vector2D | getProjectionOn (const Vector2D &v) const |
| Vector2D | getUnitVector () const |
| Vector2D | getOrthogonalVector () const |
| double | getAngle (const Vector2D &v) const |
Unsigned angle to v via acos of the normalized dot product. | |
| double | getArea (const Vector2D &v) const |
| Vector2D | rotate (double angle) |
| Rotated copy; this vector is unchanged. | |
| bool | rotateIt (double angle) |
Rotate in place by angle radians (same convention as rotate()). | |
| std::string | print () |
| Human-readable representation for debugging. | |
Public Attributes | |
| double | x |
| X component. | |
| double | y |
| Y component. | |
2D vector with the usual linear algebra: dot product, determinant, projection, rotation, angles.
operator* between vectors is the dot product; use det() for the 2D cross product. Angles are always radians. Most operations return a new vector; the *It / make* / set* variants modify in place. Note that in the screen coordinate system used by Box/Bitmap (y down), a mathematically counter-clockwise rotation appears clockwise on screen.
Definition at line 656 of file MathClasses.h.
| cmlabs::Vector2D::Vector2D | ( | ) |
Zero vector.
Definition at line 924 of file MathClasses.cpp.
Referenced by det(), getAngle(), getArea(), getOrthogonalVector(), getProjectionOn(), getUnitVector(), isOrthogonalWith(), isParallelWith(), operator*(), operator*(), operator*=(), operator+(), operator+(), operator+=(), operator+=(), operator-(), operator-(), operator-=(), operator-=(), operator==(), and rotate().
| cmlabs::Vector2D::Vector2D | ( | double | x, |
| double | y ) |
|
virtual |
Definition at line 926 of file MathClasses.cpp.
| double cmlabs::Vector2D::det | ( | const Vector2D & | v | ) | const |
2D cross product / determinant (x*v.y - y*v.x); sign gives turn direction.
Definition at line 1046 of file MathClasses.cpp.
References Vector2D(), x, and y.
Referenced by getArea(), isParallelWith(), and cmlabs::MathClasses_UnitTest().
| double cmlabs::Vector2D::getAngle | ( | const Vector2D & | v | ) | const |
Unsigned angle to v via acos of the normalized dot product.
Definition at line 1098 of file MathClasses.cpp.
References length(), and Vector2D().
| double cmlabs::Vector2D::getArea | ( | const Vector2D & | v | ) | const |
v (|det|). Definition at line 1105 of file MathClasses.cpp.
References det(), and Vector2D().
| Vector2D cmlabs::Vector2D::getOrthogonalVector | ( | ) | const |
Definition at line 1094 of file MathClasses.cpp.
References Vector2D(), x, and y.
Referenced by cmlabs::MathClasses_UnitTest().
v. Definition at line 1058 of file MathClasses.cpp.
References getUnitVector(), and Vector2D().
Referenced by cmlabs::MathClasses_UnitTest().
| Vector2D cmlabs::Vector2D::getUnitVector | ( | ) | const |
Definition at line 1067 of file MathClasses.cpp.
References length(), Vector2D(), x, and y.
Referenced by getProjectionOn(), and cmlabs::MathClasses_UnitTest().
| double cmlabs::Vector2D::getX | ( | ) | const |
| double cmlabs::Vector2D::getY | ( | ) | const |
| bool cmlabs::Vector2D::isOrthogonalWith | ( | const Vector2D & | v | ) | const |
Definition at line 1050 of file MathClasses.cpp.
References Vector2D().
| bool cmlabs::Vector2D::isParallelWith | ( | const Vector2D & | v | ) | const |
Definition at line 1054 of file MathClasses.cpp.
References det(), and Vector2D().
| double cmlabs::Vector2D::length | ( | ) | const |
Definition at line 1042 of file MathClasses.cpp.
Referenced by getAngle(), getUnitVector(), cmlabs::MathClasses_UnitTest(), and setLength().
| bool cmlabs::Vector2D::makeUnitVector | ( | ) |
Normalize in place.
Definition at line 1063 of file MathClasses.cpp.
References setLength().
Referenced by cmlabs::MathClasses_UnitTest().
| double cmlabs::Vector2D::operator* | ( | const Vector2D & | v | ) | const |
| Vector2D cmlabs::Vector2D::operator* | ( | double | a | ) | const |
| const Vector2D & cmlabs::Vector2D::operator*= | ( | double | a | ) |
| Vector2D cmlabs::Vector2D::operator+ | ( | double | a | ) | const |
Add scalar to each component.
Definition at line 969 of file MathClasses.cpp.
References Vector2D(), x, and y.
| const Vector2D & cmlabs::Vector2D::operator+= | ( | double | a | ) |
In-place scalar add.
Definition at line 1001 of file MathClasses.cpp.
References Vector2D(), x, and y.
| Vector2D cmlabs::Vector2D::operator- | ( | double | a | ) | const |
Subtract scalar from each component.
Definition at line 962 of file MathClasses.cpp.
References Vector2D(), x, and y.
| const Vector2D & cmlabs::Vector2D::operator-= | ( | double | a | ) |
In-place scalar subtract.
Definition at line 995 of file MathClasses.cpp.
References Vector2D(), x, and y.
| bool cmlabs::Vector2D::operator== | ( | const Vector2D & | v | ) | const |
Component equality.
Definition at line 938 of file MathClasses.cpp.
References Vector2D(), x, and y.
| double cmlabs::Vector2D::operator[] | ( | int | n | ) | const |
| std::string cmlabs::Vector2D::print | ( | ) |
Human-readable representation for debugging.
Definition at line 1038 of file MathClasses.cpp.
References cmlabs::utils::StringFormat(), x, and y.
| Vector2D cmlabs::Vector2D::rotate | ( | double | angle | ) |
Rotated copy; this vector is unchanged.
| angle | Radians, counter-clockwise in a y-up frame (appears clockwise with screen y-down coordinates). |
Definition at line 1077 of file MathClasses.cpp.
References Vector2D(), x, and y.
Referenced by cmlabs::MathClasses_UnitTest().
| bool cmlabs::Vector2D::rotateIt | ( | double | angle | ) |
Rotate in place by angle radians (same convention as rotate()).
Definition at line 1085 of file MathClasses.cpp.
| bool cmlabs::Vector2D::set | ( | const PointFloat & | p1, |
| const PointFloat & | p2 ) |
Set as p2-p1.
Definition at line 1018 of file MathClasses.cpp.
References set(), cmlabs::PointFloat::x, and cmlabs::PointFloat::y.
| bool cmlabs::Vector2D::set | ( | double | x, |
| double | y ) |
| bool cmlabs::Vector2D::set | ( | double | x1, |
| double | y1, | ||
| double | x2, | ||
| double | y2 ) |
Set as (x2-x1, y2-y1).
Definition at line 1022 of file MathClasses.cpp.
References set().
| bool cmlabs::Vector2D::setLength | ( | double | l | ) |
Rescale to length l, keeping direction.
Definition at line 1029 of file MathClasses.cpp.
References length(), x, and y.
Referenced by makeUnitVector(), and cmlabs::MathClasses_UnitTest().
| bool cmlabs::Vector2D::setX | ( | double | v | ) |
| bool cmlabs::Vector2D::setY | ( | double | v | ) |
| double cmlabs::Vector2D::x |
X component.
Definition at line 663 of file MathClasses.h.
Referenced by det(), getOrthogonalVector(), getUnitVector(), getX(), length(), cmlabs::MathClasses_UnitTest(), cmlabs::Size::operator*(), operator*(), operator*(), operator*=(), cmlabs::Point::operator+(), cmlabs::PointFloat::operator+(), operator+(), operator+(), operator+=(), operator+=(), operator-(), operator-(), operator-=(), operator-=(), operator==(), operator[](), print(), rotate(), rotateIt(), set(), setLength(), setX(), Vector2D(), and Vector2D().
| double cmlabs::Vector2D::y |
Y component.
Definition at line 664 of file MathClasses.h.
Referenced by det(), getOrthogonalVector(), getUnitVector(), getY(), length(), cmlabs::MathClasses_UnitTest(), cmlabs::Size::operator*(), operator*(), operator*(), operator*=(), cmlabs::Point::operator+(), cmlabs::PointFloat::operator+(), operator+(), operator+(), operator+=(), operator+=(), operator-(), operator-(), operator-=(), operator-=(), operator==(), operator[](), print(), rotate(), rotateIt(), set(), setLength(), setY(), Vector2D(), and Vector2D().