-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVec2d.hh
37 lines (32 loc) · 883 Bytes
/
Vec2d.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
/*
@author: Xinqi Bao
2-D vector, with 2 double vaule points.
*/
#include <iostream>
#include "Vec3d.hh"
class Vec2d {
public:
double x, y;
bool equal(const Vec2d& v) const;
bool equal(const Vec2d* v) const;
double sum() const;
Vec2d() {}
Vec2d(double x, double y) : x(x), y(y) {}
Vec2d( const Vec3d& v1, const Vec3d& v2, double z) {
x = (v1.x - v2.x) * (z - v1.z) / (v1.z - v2.z) + v1.x;
y = (v1.y - v2.y) * (z - v1.z) / (v1.z - v2.z) + v1.y;
}
friend std::istream& operator >>(std::istream& s, Vec2d& v) {
return s >> v.x >> v.y;
}
friend std::istream& operator >>(std::istream& s, Vec2d* v) {
return s >> v->x >> v->y;
}
friend std::ostream& operator <<(std::ostream& s, const Vec2d& v) {
return s << v.x << "," << v.y;
}
friend std::ostream& operator <<(std::ostream& s, const Vec2d* v) {
return s << v->x << "," << v->y;
}
};