Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h> //All main STD libraries
- using namespace std;
- // Point or Vector 2D class (by Imanol SAGA)
- class V2
- {
- public:
- float x,y;
- V2(){ x=0.1; y=0.1; }
- V2(int _x, int _y){ x=_x; y=_y; }
- V2(V2 *v){ x=v->x; y=v->y; }
- V2(int range){ float rd=range*0.5; x=(-rd)+(rand()%range); y=(-rd)+(rand()%range); }
- void set(V2 &v){ x=v.x; y=v.y; }
- inline void never0(){ x=x!=0?x:0.1; y=y!=0?y:0.1; }
- inline void add(V2 &v){ x+=v.x; y+=v.y; }
- inline void subs(V2 &v){ x-=v.x; y-=v.y; }
- inline void mult(float n){ x*=n; y*=n; }
- inline void div(float n){ never0(); n=n!=0?n:0.1; x/=n; y/=n; }
- inline float mag2(){ return((x*x)+(y*y)); }
- inline float mag(){ return(sqrt(mag2())); }
- inline void norm(){ div(mag()); }
- inline void setMag(float m){ norm(); mult(m); }
- inline float dist2(V2 &p){ return(pow(x-p.x,2)+pow(y-p.y,2)); }
- inline float dist(V2 &p){ return(sqrt(dist2(p))); }
- };
- int main(){ cout<< "You are welcome"<< endl; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement