vector2d.cpp
资源名称:package.rar [点击查看]
上传用户:chinasdcnc
上传日期:2022-07-02
资源大小:2702k
文件大小:2k
源码类别:
分形几何
开发平台:
Visual C++
- //
- // Delaunay Triangulation
- //
- // Homework of CG lesson (Fall 2009) in Tsinghua University.
- // All rights reserved.
- //
- // temp include, delete later if necessary
- #include "stdafx.h"
- #include "vector2d.h"
- // C++ headers
- #include <cmath>
- Vector2d::Vector2d(void)
- :x(0), y(0)
- {
- }
- Vector2d::Vector2d(double tx, double ty)
- :x(tx), y(ty)
- {
- }
- Vector2d::Vector2d(const Vector2d& vect)
- {
- x = vect.x;
- y = vect.y;
- }
- double Vector2d::norm(void) const
- {
- return sqrt(x * x + y * y);
- }
- double Vector2d::squareNorm(void) const
- {
- return x * x + y * y;
- }
- bool Vector2d::normalize(void)
- {
- double len = this->norm();
- if (len == 0.0)
- {
- return false;
- }
- else
- {
- x /= len;
- y /= len;
- return true;
- }
- }
- double Vector2d::dot(const Vector2d& vect)
- {
- return (x * vect.x + y * vect.y);
- }
- Vector2d Vector2d::operator*(double c) const
- {
- return Vector2d(c * x, c * y);
- }
- Vector2d& Vector2d::operator*=(double c)
- {
- x *= c;
- y *= c;
- return *this;
- }
- Vector2d Vector2d::operator+(const Vector2d& vect) const
- {
- return Vector2d(x + vect.x, y + vect.y);
- }
- Vector2d& Vector2d::operator+=(const Vector2d& vect)
- {
- x += vect.x;
- y += vect.y;
- return *this;
- }
- Vector2d Vector2d::operator-(const Vector2d& vect) const
- {
- return Vector2d(x - vect.x, y - vect.y);
- }
- Vector2d& Vector2d::operator-=(const Vector2d& vect)
- {
- x -= vect.x;
- y -= vect.y;
- return *this;
- }