Skip to content
This repository has been archived by the owner on Mar 25, 2019. It is now read-only.

Commit

Permalink
Add prism id
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonGerasimov committed May 18, 2015
1 parent f6d6530 commit d087581
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 146 deletions.
152 changes: 6 additions & 146 deletions main/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,147 +411,6 @@ class Disc : public Device{ // n > 1 !!!




/*
class Lens_ras : public Device{
public:
float deg, f, l;
public:
Lens_ras ( float x, float y, float l_0, float deg_0, float f_0){ //deg from vertical 0 <= deg < 90 !!! against hour ;
x1 = x - (float)(l_0/2) * sin (deg_0 * PI / 180) ;
x2 = x + (float)(l_0/2) * sin (deg_0 * PI / 180);
y1 = y - (float)(l_0/2) * cos (deg_0 * PI / 180);
y2 = y + (float)(l_0/2) * cos (deg_0 * PI / 180);
l = l_0;
f = f_0;
deg = deg_0;
}
point * cross_point (RAY * r) const {
point * p = new point ();
if ((orient (this->x1,this->y1,this->x2,this->y2,r->x,r->y,1) < 0) && ((r->deg <= 90) || (r->deg >= 270))){
cout << "c_here_1 \n";
float det = this->y2 - this->y1 - tan (r->deg * PI / 180) * (this->x1 - this->x2);
float det_1 = this->y2 * this->x1 - this->y1 * this->x2 - (this->x1 - this->x2) * (r->y + tan (r->deg * PI / 180) * r->x);
float det_2 = (this->y2 - this->y1) * (r->y + tan (r->deg * PI / 180) * r->x) - (this->y2 * this->x1 - this->y1 * this->x2) * tan (r->deg * PI / 180);
p->x = (float)det_1/det;
p->y = (float)det_2/det;
if (( p->x >= x1 ) && ( p->x <= x2 ) && ( p->y >= y1 ) && ( p->y <= y2 ))
return p;
}
if ((orient (this->x1,this->y1,this->x2,this->y2,r->x,r->y,1) > 0) && ((r->deg >= 90) && (r->deg <= 270))) {
cout << "c_here_2 \n";
float det = this->y2 - this->y1 - tan (r->deg * PI / 180) * (this->x1 - this->x2);
float det_1 = this->y2 * this->x1 - this->y1 * this->x2 - (this->x1 - this->x2) * (r->y + tan (r->deg * PI / 180) * r->x);
float det_2 = (this->y2 - this->y1) * (r->y + tan (r->deg * PI / 180) * r->x) - (this->y2 * this->x1 - this->y1 * this->x2) * tan (r->deg * PI / 180);
p->x = (float)det_1/det;
p->y = (float)det_2/det;
if (( p->x >= x1 ) && ( p->x <= x2 ) && ( p->y >= y1 ) && ( p->y <= y2 ))
return p;
}
return NULL;
}
void change_direction(RAY * r, point * p ) const
{
float l_1 = 0;
float alpha = 0;
float alpha_r = 0;
float c = 0 ;
float length = (float) sqrt ((r->x - (this->x1 + this->x2)/2) * (r->x - (this->x1 + this->x2)/2)+ (r->y - (this->y1 + this->y2)/2) * (r->y - (this->y1 + this->y2)/2)) ;
float line_tg = fabs ((float)((r->y - (this->y1 + this->y2)/2) / ((this->x1 + this->x2)/2 - r->x))) ;
//cout << " line_tg_prev = " << line_tg << "\n";
float line_deg = atan (line_tg) * 180 / PI;
cout << "line_deg_prev = " << line_deg <<"\n";
if (orient (this->x1,this->y1,this->x2,this->y2,r->x,r->y,1) < 0) {
if (r->y <= (this->y1 + this->y2)/2)
line_deg = this->deg + line_deg;
else
line_deg = fabs (line_deg - this->deg);
}
else {
if (r->y >= (this->y1 + this->y2)/2)
line_deg = this->deg + line_deg;
else
line_deg = fabs (line_deg - this->deg);
}
cout << "line_deg = " << line_deg << "\n";
line_tg = tan (line_deg * PI / 180);
//cout << " line_tg = " << line_tg << "\n";
float a = length * cos (atan (line_tg));
//cout << " a = " << a << "\n";
float b = (float) (this->f * a / (a + this->f));
//cout << " b = " << b << "\n";
c = sqrt ((p->x - (this->x1 + this->x2)/2) * (p->x - (this->x1 + this->x2)/2)+ (p->y - (this->y1 + this->y2)/2) * (p->y - (this->y1 + this->y2)/2)) ;
if (((orient (this->x1, this->y1 + this->l / 2 /cos (this->deg * PI / 180),this->x2, this->y2 - l / 2 /cos (this->deg * PI / 180), r->x, r->y,this->deg) >= 0) && (orient (this->x1, this->y1 + this->l / 2 /cos (this->deg * PI / 180),this->x2, this->y2 - this->l / 2 /cos (this->deg * PI / 180), p->x, p->y,this->deg) <= 0)) || ((orient (this->x1, this->y1 + this->l / 2 /cos (this->deg * PI / 180),this->x2, this->y2 - this->l / 2 /cos (this->deg * PI / 180), r->x, r->y,this->deg) <= 0) && (orient (this->x1, this->y1 + this->l / 2 /cos (this->deg * PI / 180),this->x2, this->y2 - this->l / 2 /cos (this->deg * PI / 180), p->x, p->y,this->deg) >= 0))) { // точка пересечения и координата луча по разные стороны от опт.оси
l_1 = c + (float) b * line_tg;
cout << "here \n";
alpha = atan ((float) (l_1 / b)) * 180 / PI;
alpha_r = 180 -alpha ;
if ((orient (this->x1, this->y1 + this->l / 2 /cos (this->deg * PI / 180),this->x2, this->y2 - this->l / 2 /cos (this->deg * PI / 180), r->x, r->y,this->deg) >= 0) && (orient (this->x1, this->y1 + this->l / 2/cos (this->deg * PI / 180),this->x2, this->y2 - this->l / 2/cos (this->deg * PI / 180), p->x, p->y,this->deg) <= 0)) { //точка координата луча выше точка пересечения ниже
alpha_r = alpha_r + 2 * alpha;
alpha = 360 - alpha;
cout << " here_0 \n";
}
}
else { //точка персечкения и полоожение луча по одну сторону от опт.оси
l_1 = fabs (c - (float) b * line_tg);
alpha = atan ((float) (l_1 / b)) * 180 / PI;
alpha_r = 180 -alpha ;
cout << "here_here \n";
if ((orient (this->x1, this->y1 + this->l / 2/cos (this->deg * PI / 180),this->x2, this->y2 - this->l / 2 /cos (this->deg * PI / 180), r->x, r->y,this->deg) >= 0) && (orient (this->x1, this->y1 + (this->l / 2 - b * line_tg) / cos (this->deg * PI / 180) ,this->x2, this->y2 - (this->l / 2 + b * line_tg) / cos (this->deg * PI / 180), p->x, p->y,this->deg) <= 0)){ // луч выше опт.оси точка пересечения под всмогат.линией сверху
alpha_r = alpha_r + 2 * alpha;
alpha = 360 - alpha;
cout << "here_1 \n";
}
if ((orient (this->x1, this->y1 + this->l / 2 /cos (this->deg * PI / 180),this->x2, this->y2 - this->l / 2 /cos (this->deg * PI / 180), r->x, r->y,this->deg) <= 0) && (orient (this->x1, this->y1 + (this->l / 2 + b * line_tg) / cos (this->deg * PI / 180) ,this->x2, this->y2 - (this->l / 2 - b * line_tg) / cos (this->deg * PI / 180), p->x, p->y,this->deg) <= 0)) { // луч ниже опт.оси точка пересечения над всмогат.линией снизу
alpha_r = alpha_r + 2 * alpha;
alpha = 360 - alpha;
cout << "alpha =" << alpha << "\n";
cout << "here_2 \n";
}
}
if (orient (this->x1,this->y1,this->x2,this->y2,r->x,r->y,1) < 0)
r->deg = alpha ;
else
r->deg = alpha_r;
if (orient (this->x1,this->y1,this->x2,this->y2,r->x,r->y,1) < 0) {
if ((r->deg + this->deg - 360) > 0)
r->deg = (r->deg + this->deg - 360);
else
r->deg = r->deg + this->deg;
}
else {
r->deg = r->deg + this->deg;
}
r->x = p->x;
r->y = p->y;
}
const char *getID() const{
return "Lens_ras";
}
~Lens_ras ()
{
cout << "Destructure of the Lens_ras" << "\n";
}
};
*/


class Lens : public Device{
public:
float deg, f, l;
Expand Down Expand Up @@ -1597,15 +1456,16 @@ class Prism : public Device {
}

}
int getID(){
return 5;
}

const char *getID() const {
return "Prism";
}
// const char *getID() const {
// return "Prism";
// }

~Prism()
{
cout << "Destructure of the " << this->getID() << "\n";
}
};


12 changes: 12 additions & 0 deletions main/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ for(int I=0; I<my_laser_ray.size(); I++)
}
recv(cs, temp, 1, 0);
}
if (my_device[num]->getID()==5){
cross = my_device[num]->cross_point(my_laser_ray[I]);
sprintf(buf_, "%f %f %f %f %c", my_laser_ray[I]->x, my_laser_ray[I]->y, cross->x, cross->y, '\0');//new dot
if(send(cs, buf_, strlen(buf_)+1, MSG_NOSIGNAL)==-1){
perror("Can't send:");
return NULL;
}
recv(cs, temp, 1, 0);
float tx=cross->x;
float ty=cross->y;
my_device[num]->change_direction(my_laser_ray[I], cross);
}
}
else{
break;
Expand Down

0 comments on commit d087581

Please sign in to comment.