Guest User

Untitled

a guest
May 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. class Vector {
  2. double x_, y_;
  3. public:
  4. Vector(double x = 0, double y = 0);
  5. void print(int precision = 2, bool newLine = true);
  6. void truncate(double length);
  7. bool isOrtho(const Vector& v) const;
  8. static float dot(const Vector& v1, const Vector& v2);
  9. static float cross(const Vector& v1, const Vector& v2);
  10. friend ostream& operator<<(ostream& os, const Vector& v);
  11. };
  12.  
  13. Vector::Vector(double x , double y )
  14. {
  15. x_ = x ;
  16. y_ = y ;
  17. }
  18. void Vector::print(int precision , bool newLine)
  19. {
  20. cout << fixed << setprecision(precision) << "(" << x_ << ", " << y_ << ")";
  21. if (newLine) cout << endl;
  22. }
  23. void Vector::truncate(double length)
  24. {
  25. x_-=length;
  26. y_-=length;
  27. }
  28. bool Vector::isOrtho(const Vector& v ) const {
  29. return ( x_*v.x_ + y_*v.y_ == 0 );
  30. }
  31. float Vector::dot(const Vector& v1, const Vector& v2) {
  32. return (v1.x_*v2.x_ + v1.y_*v2.y_);
  33. }
  34. ostream& operator<<(ostream& os,const Vector& v)
  35. {
  36. os << "(" << v.x_ << ", " << v.y_ << ")" ;
  37. return os;
  38. }
  39. float Vector::cross(const Vector& v1, const Vector& v2){
  40. return (v1.x_*v2.y_ - v1.y_*v2.x_) ;
  41. }
Add Comment
Please, Sign In to add comment