You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.7 KiB
54 lines
1.7 KiB
#include "math/Mmn.h"
|
|
#include <time.h>
|
|
#include <sys/timeb.h>
|
|
|
|
int main(void) {
|
|
double x0=-1, x1=1, y0=0, y1=0;
|
|
double x0s=-1, x1s=1, y0s=1, y1s=-2;
|
|
time_t secs;
|
|
unsigned short ms;
|
|
struct timeb tb1;
|
|
struct timeb tb2;
|
|
int i;
|
|
double x, y;
|
|
|
|
double a[2][3]={{y1-y0, -(x1-x0), -(x1*y0-y1*x0)},
|
|
{y1s-y0s, -(x1s-x0s), -(x1s*y0s-y1s*x0s)}};
|
|
Mmn<double> mat((double*)a, 2, 3);
|
|
|
|
mat.print();
|
|
ftime(&tb1);
|
|
for(i=0; i<1000; i++)
|
|
mat.solve();
|
|
ftime(&tb2);
|
|
|
|
cout << tb1.time << ":" << tb1.millitm << "\n";
|
|
cout << tb2.time << ":" << tb2.millitm << "\n";
|
|
cout << tb2.time-tb1.time << ":" << tb2.millitm-tb1.millitm << "\n";
|
|
|
|
ftime(&tb1);
|
|
for(i=0; i<1000; i++) {
|
|
x=x0+((((x1s-x0s)*(y0-y0s))+((y1s-y0s)*(x0s-x0)))/
|
|
(((x1-x0)*(y1s-y0s))-((y1-y0)*(x1s-x0s))))*(x1-x0);
|
|
|
|
y=y0+((((x1s-x0s)*(y0-y0s))+((y1s-y0s)*(x0s-x0)))/
|
|
(((x1-x0)*(y1s-y0s))-((y1-y0)*(x1s-x0s))))*(y1-y0);
|
|
}
|
|
ftime(&tb2);
|
|
|
|
cout << tb1.time << ":" << tb1.millitm << "\n";
|
|
cout << tb2.time << ":" << tb2.millitm << "\n";
|
|
cout << tb2.time-tb1.time << ":" << tb2.millitm-tb1.millitm << "\n";
|
|
|
|
/*
|
|
* Fazit: nach einigen Testläufen mit diesem Programm hat sich ergeben, das
|
|
* beide Methoden keine messbaren Zeitunterschied im 1000stel Sekundenbereich
|
|
+ haben, daher faworisiere ich die Methode über das lösen des
|
|
* Gleichungssystems, da diese universeller (auch mit 3 Geraden) einsetzbar
|
|
* und auch verständlicher ist (man braucht keine Formeln herleiten.
|
|
*
|
|
* Wenn ich die berechnungen 1000 mal ausführe habe die Gleichungen einen
|
|
* deutlichen vorteil. Daher nehme ich wohl doch sie...
|
|
*/
|
|
return 0;
|
|
}
|