Created
March 15, 2018 18:27
-
-
Save sienki-jenki/7b56ee45c61bd64e7098b91bf4dcce46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <math.h> | |
#include <time.h> | |
using namespace std; | |
class wektor{ | |
public: | |
float x,y,r,fi; | |
void wypiszxyf(); | |
void obliczxy(); | |
void losujxy(); | |
void normuj(); | |
void obliczr(); | |
void obliczkat(); | |
void przypiszxy(float xx,float yy); | |
void obrot(float kat); | |
}; | |
void wektor::obliczxy(){ | |
x=r*cos(fi); | |
y=r*sin(fi); | |
}; | |
void wektor::obrot(float kat){ | |
fi+=kat*M_PI/180; | |
obliczxy(); | |
}; | |
void wektor::obliczkat(){ | |
fi=atan(y/x); | |
}; | |
void wektor::wypiszxyf(){ | |
cout<<"{"<<x<<","<<y<<"},"<<endl; | |
//cout<<"Kat pomiedzy x a r wynosi: "<<fi<<endl; | |
}; | |
void wektor::losujxy(){ | |
x=rand()%10; | |
y=rand()%10; | |
}; | |
void wektor::normuj(){ | |
x/=r; | |
y/=r; | |
r=1; | |
}; | |
void wektor::obliczr(){ | |
r = sqrt(pow(x,2)+pow(y,2)); | |
} | |
class kulka{ | |
public: | |
wektor poloz; | |
wektor predk; | |
float fi; | |
void lec(int t); | |
void skrec(float kat); | |
}; | |
void wektor::przypiszxy(float xx,float yy){ | |
x=xx; | |
y=yy; | |
}; | |
void kulka::lec(int t){ | |
poloz.x+=t*predk.x; | |
poloz.y+=t*predk.y; | |
}; | |
void kulka::skrec(float kat){ | |
predk.obliczr(); | |
predk.obliczkat(); | |
predk.fi+=kat*M_PI/180; | |
predk.obliczxy(); | |
}; | |
int main(){ | |
srand(time(NULL)); | |
int ilosc_rogow; | |
cout<<"Podaj ilosc rogow: "; | |
cin>>ilosc_rogow; | |
float step = M_PI/ilosc_rogow; | |
float rot = M_PI /2*3; | |
kulka k1; | |
k1.poloz.przypiszxy(2.1,0.9); | |
k1.predk.przypiszxy(1,1); | |
for(int c=0;c<ilosc_rogow;c++){ | |
/*k1.skrec(rand()%360); | |
k1.lec(1); | |
//k1.predk.wypiszxyf(); | |
k1.poloz.wypiszxyf();*/ | |
k1.skrec(rot); | |
k1.lec(1); | |
rot = rot + step; | |
k1.poloz.wypiszxyf(); | |
k1.skrec(rot); | |
k1.lec(1); | |
rot = rot + step; | |
k1.poloz.wypiszxyf(); | |
}; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment