Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iomanip>
- #include <iostream>
- using namespace std;
- struct Point {
- double x;
- double y;
- };
- struct Vector {
- double x;
- double y;
- };
- Vector operator-(const Point& p1, const Point& p2) {return {p1.x - p2.x, p1.y - p2.y};}
- Vector operator+(const Vector& v1, const Vector& v2) {return {v1.x + v2.x, v1.y + v2.y};}
- Vector operator-(const Vector& v1, const Vector& v2) {return {v1.x - v2.x, v1.y - v2.y};}
- Point operator+(const Point& p, const Vector& v) {return {p.x + v.x, p.y + v.y};}
- double DotProduct(const Vector& v1, const Vector& v2) {return v1.x * v2.x + v1.y * v2.y;}
- double CrossProduct(const Vector& v1, const Vector& v2) {return v1.x * v2.y - v1.y * v2.x;}
- int main() {
- Vector v1 = {3, 4}, v2 = {0, 5};
- cout << DotProduct(v1, v2) << endl;
- cout << CrossProduct(v2, v1) << endl;
- Point p1{2, 2}, p2{6, 5};
- Vector v3 = p2 - p1;
- cout << v3.x << " " << v3.y << endl;
- return 0;
- }
- int main1() {
- int n = 0;
- Point p;
- p.x = 5.0;
- p.y = acos(-1);
- cout << fixed << p.x << " " << setprecision(10) << p.y << endl;
- cout << p.x << " " << p.y << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement