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

Commit

Permalink
Merge pull request #6 from AntonGerasimov/master
Browse files Browse the repository at this point in the history
Й
  • Loading branch information
Stuv7CB committed May 18, 2015
2 parents 9dea1d7 + d087581 commit a4c8473
Show file tree
Hide file tree
Showing 18 changed files with 5,077 additions and 373 deletions.
526 changes: 423 additions & 103 deletions device.h → 051315/first/device.h

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions 051315/first/first.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <stdio.h>
#include "device.h"
#include <math.h>


float min_(float x1, float x2){
if (x1 < x2)
return x1;
else return x2;
}
void print_(vector <Device *> my_device){
for (int i = 0; i < my_device.size(); i++){
printf("%d:%f\n", i,min_(my_device[i]->x1, my_device[i]->x2));
}
printf("\n");
}
float sqr_(float x){
return x*x;
}

int first(vector <Device *> d, RAY *r){
int ret = -1;
float x = r->x;
float y = r->y;
float rast;
float min = 100000;
for (int i = 0; i < d.size(); i++){
point *cross = NULL;
cross = d[i] -> cross_point(r);
if (cross != NULL){
float xp = cross -> x;
float yp = cross -> y;
rast = sqrt(sqr_(x - xp)+sqr_(y - yp));
}
else{
rast = 1000000;
}
if (rast < min){
min = rast;
ret = i;
}
}
return ret;
}

int main(){
vector <Device *> my_device;
Device *d1 = new Lens(30, 0, 10, 5, 0);
Device *d2 = new Lens(10, 0, 10, 10, 0);
Device *d3 = new Lens(50, 0, 10, 20, 0);
my_device.push_back(d1);
my_device.push_back(d2);
my_device.push_back(d3);
RAY *r = new RAY();
r->set_ray_pos(40, 0, 10);
int q = first(my_device, r);
printf("%d\n", q);
// sort_(my_device);
return 0;
}
71 changes: 71 additions & 0 deletions 051315/first/first.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <stdio.h>
#include "device.h"
#include <math.h>


float min_(float x1, float x2){
if (x1 < x2)
return x1;
else return x2;
}
void print_(vector <Device *> my_device){
for (int i = 0; i < my_device.size(); i++){
printf("%d:%f\n", i,min_(my_device[i]->x1, my_device[i]->x2));
}
printf("\n");
}
float sqr_(float x){
return x*x;
}

int first(vector <Device *> d, RAY *r){
int ret = -1;
float x = r->x;
float y = r->y;
float rast;
float min = 100000;
if (d.size==0){
return ret;
}
for (int i = 0; i < d.size(); i++){
point *cross = NULL;
cross = d[i] -> cross_point(r);
if (cross != NULL){
float xp = cross -> x;
float yp = cross -> y;
rast = sqrt(sqr_(x - xp)+sqr_(y - yp));
}
else{
rast = 1000000;
}
if (rast < min){
min = rast;
ret = i;
}
}
return ret;
}
int first_s(vector <SCREEN *> d, RAY *r){
int ret = -1;
float x = r->x;
float y = r->y;
float rast;
float min = 100000;
for (int i = 0; i < d.size(); i++){
point *cross = NULL;
cross = d[i] -> cross_point(r);
if (cross != NULL){
float xp = cross -> x;
float yp = cross -> y;
rast = sqrt(sqr_(x - xp)+sqr_(y - yp));
}
else{
rast = 1000000;
}
if (rast < min){
min = rast;
ret = i;
}
}
return ret;
}
Loading

0 comments on commit a4c8473

Please sign in to comment.