Created
February 26, 2014 16:21
-
-
Save siviae/9232922 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <gmpxx.h> | |
#include <gmp.h> | |
using namespace std; | |
template<class S> | |
struct point_t{ | |
S x; | |
S y; | |
// template<class S> | |
// point_t(const& S x, const& S y){ | |
//} | |
}; | |
double cross(double ax,double ay, | |
double bx,double by, | |
double cx, double cy){ | |
return (ax-cx)*(by-cy) - (bx-cx)*(ay-cy); | |
} | |
mpq_class cross(mpq_class ax,mpq_class ay, | |
mpq_class bx,mpq_class by, | |
mpq_class cx, mpq_class cy){ | |
return (ax-cx)*(by-cy) - (bx-cx)*(ay-cy); | |
} | |
gmp_randclass r(gmp_randinit_default); | |
int main() | |
{ | |
while(true){ | |
mpf_class axt = r.get_f(); | |
double ax = axt.get_d(); | |
mpf_class ayt = r.get_f(); | |
double ay = ayt.get_d(); | |
mpf_class bxt = r.get_f(); | |
double bx = bxt.get_d(); | |
mpf_class byt = r.get_f(); | |
double by = byt.get_d(); | |
mpf_class tt = r.get_f(); | |
double t = tt.get_d(); | |
double cx = (bx-ax)*t+ax; | |
double cy = (by-ay)*t+ay; | |
double res1 = cross(ax,ay,bx,by,cx,cy); | |
mpq_class res2 = cross(mpq_class(ax),mpq_class(ay), | |
mpq_class(bx),mpq_class(by), | |
mpq_class(cx),mpq_class(cy)); | |
if(sgn(mpf_class(res1))*sgn(res2)<0){ | |
cout << ax << " "<< ay << " "<< | |
bx << " "<< by << " "<< | |
cx << " "<< cy << " "<< endl; | |
return 0; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment