123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- #include "vector3d.h"
- #include <math.h>
-
- Vector3D::Vector3D(double x, double y, double z)
- : _x(x)
- , _y(y)
- , _z(z)
- {
- }
-
- Vector3D::Vector3D(const Vector3D &other)
- : _x(other._x)
- , _y(other._y)
- , _z(other._z)
- {
- }
-
- double Vector3D::getX() const
- {
- return _x;
- }
-
- Vector3D& Vector3D::setX(double x)
- {
- _x = x;
- return *this;
- }
- double Vector3D::getY() const
- {
- return _y;
- }
-
- Vector3D& Vector3D::setY(double y)
- {
- _y = y;
- return *this;
- }
- double Vector3D::getZ() const
- {
- return _z;
- }
-
- Vector3D& Vector3D::setZ(double z)
- {
- _z = z;
- return *this;
- }
-
- bool Vector3D::isNull() const
- {
- return _x == 0 && _y == 0 && _z == 0;
- }
-
- bool Vector3D::equal(const Vector3D &other) const
- {
- return _x == other._x && _y == other._y && _z == other._z;
- }
-
- Vector3D &Vector3D::add(double k)
- {
- return add(Vector3D(k, k, k));
- }
-
- Vector3D &Vector3D::add(double x, double y, double z)
- {
- return add(Vector3D(x, y, z));
- }
-
- Vector3D& Vector3D::add(const Vector3D &other)
- {
- _x += other._x;
- _y += other._y;
- _z += other._z;
- return *this;
- }
-
- Vector3D &Vector3D::sub(double k)
- {
- return sub(Vector3D(k, k, k));
- }
-
- Vector3D &Vector3D::sub(double x, double y, double z)
- {
- return sub(Vector3D(x, y, z));
- }
-
- Vector3D& Vector3D::sub(const Vector3D &other)
- {
- _x -= other._x;
- _y -= other._y;
- _z -= other._z;
- return *this;
- }
-
- Vector3D &Vector3D::mult(double k)
- {
- _x *= k;
- _y *= k;
- _z *= k;
- return *this;
- }
-
- Vector3D &Vector3D::div(double k)
- {
- _x /= k;
- _y /= k;
- _z /= k;
- return *this;
- }
-
- double Vector3D::dotProduct(double x, double y, double z) const
- {
- return dotProduct(Vector3D(x, y, z));
- }
-
- double Vector3D::dotProduct(const Vector3D &other) const
- {
- return (_x * other._x) + (_y * other._y) + (_z * other._z);
- }
-
- double Vector3D::norm() const
- {
- return sqrt((_x * _x) + (_y * _y) + (_z * _z));
- }
-
- Vector3D Vector3D::operator+()
- {
- return *this;
- }
-
- Vector3D Vector3D::operator+(const double &k)
- {
- return Vector3D(*this).add(k);
- }
-
- Vector3D &Vector3D::operator+=(const double &k)
- {
- return add(k);
- }
-
- Vector3D Vector3D::operator+(const Vector3D &other)
- {
- return Vector3D(*this).add(other);
- }
-
- Vector3D &Vector3D::operator+=(const Vector3D &other)
- {
- return add(other);
- }
-
- Vector3D Vector3D::operator-()
- {
- return Vector3D(-_x, -_y, -_z);
- }
-
- Vector3D Vector3D::operator-(const double &k)
- {
- return Vector3D(*this).sub(k);
- }
-
- Vector3D &Vector3D::operator-=(const double &k)
- {
- return sub(k);
- }
-
- Vector3D Vector3D::operator-(const Vector3D &other)
- {
- return Vector3D(*this).sub(other);
- }
-
- Vector3D &Vector3D::operator-=(const Vector3D &other)
- {
- return sub(other);
- }
-
- Vector3D Vector3D::operator*(const double &k)
- {
- return Vector3D(*this).mult(k);
- }
-
- Vector3D &Vector3D::operator*=(const double &k)
- {
- return mult(k);
- }
-
- double Vector3D::operator*(const Vector3D &other)
- {
- return Vector3D(*this).dotProduct(other);
- }
-
- Vector3D &Vector3D::operator*=(const Vector3D &other)
- {
- dotProduct(other);
- return *this;
- }
-
- Vector3D Vector3D::operator/(const double &k)
- {
- return Vector3D(*this).div(k);
- }
-
- Vector3D &Vector3D::operator/=(const double &k)
- {
- return div(k);
- }
-
- bool Vector3D::operator==(const Vector3D &other)
- {
- return equal(other);
- }
-
- bool Vector3D::operator!=(const Vector3D &other)
- {
- return !equal(other);
- }
-
- bool Vector3D::operator!()
- {
- return isNull();
- }
-
- Vector3D::operator bool()
- {
- return !isNull();
- }
|