cpp/geometry/linevec.hpp
Depends on
Required by
Verified with
Code
#pragma once
#include "./vec.hpp"
#include "./point.hpp"
#include "./line-segment.hpp"
struct LineVec{
Point base;
Vec vec;
LineVec(LineSegment ls){
base = ls.first;
vec = ls.second - ls.first;
}
};
#line 2 "cpp/geometry/vec.hpp"
struct Vec{
long double x,y;
Vec operator*(long double a){
return {x*a, y*a};
}
Vec operator/(long double a){
return {x/a, y/a};
}
friend ostream &operator<<(ostream &os, const Vec &p){
return os << p.x << " " << p.y;
}
};
long double magnitude(Vec v){
return sqrt(v.x*v.x+v.y*v.y);
}
Vec standardize(Vec v){
return v/magnitude(v);
}
#line 3 "cpp/geometry/point.hpp"
struct Point{
long double x,y;
Vec operator-(Point b){
return {x-b.x, y-b.y};
}
Point operator+(long double a){
return {x+a, y+a};
}
Point operator+(Vec v){
return {x+v.x, y+v.y};
}
friend istream &operator>>(istream &is, Point &p){
long double a,b;
cin>>a>>b;
p = Point({a,b});
return (is);
}
friend ostream &operator<<(ostream &os, const Point &p){
return os << p.x << " " << p.y;
}
};
#line 2 "cpp/geometry/line-segment.hpp"
#line 4 "cpp/geometry/line-segment.hpp"
struct LineSegment{
Point first, second;
LineSegment(Point a, Point b):first(a),second(b){}
};
#line 5 "cpp/geometry/linevec.hpp"
struct LineVec{
Point base;
Vec vec;
LineVec(LineSegment ls){
base = ls.first;
vec = ls.second - ls.first;
}
};
Back to top page