Skip to content

Instantly share code, notes, and snippets.

Created April 16, 2011 18:08
Show Gist options
  • Save anonymous/923360 to your computer and use it in GitHub Desktop.
Save anonymous/923360 to your computer and use it in GitHub Desktop.
#include <math.h>
#define _USE_MATH_DEFINES
#include <iostream>
double returnrad(double f1,double f2,double f3,double t1,double t2,double t3){
int count,change=45;
double xyrz,xry,Lengthofxztoy,Lengthofxtoy;
Lengthofxztoy=sqrt(((t1-f1)*(t1-f1)+(t3-f3)*(t3-f3)))/sqrt(((t1-f1)*(t1-f1)+(t2-f2)*(t2-f2)+(t3-f3)*(t3-f3)));//xz平面に対するcos
Lengthofxtoy=sqrt((t1-f1)*(t1-f1))/sqrt(((t1-f1)*(t1-f1)+(t3-f3)*(t3-f3)));//xとzの角度
if(t2>f2){//以下二分木による探索
count=90;
while(change>1){
if(cos(360/M_PI*(double)count)<Lengthofxztoy){
count-=change;
}else if(cos(360/M_PI*(double)count)>Lengthofxztoy){
count+=change;
}
else{break;}
change=change/2;
}
xyrz=(double)count;
}else if(t2<f2){
count=270;
while(change>1){
if(cos(360/M_PI*(double)count)<Lengthofxztoy){
count+=change;
}else if(cos(360/M_PI*(double)count)>Lengthofxztoy){
count-=change;
}
else{break;}
change=change/2;
}
xyrz=(double)count;
}
else {xyrz=0;}
change=45;
if(t3>f3){
count=90;
while(change>1){
if(cos(360/M_PI*(double)count)<Lengthofxtoy){
count-=change;
}
else if(cos(360/M_PI*(double)count)>Lengthofxtoy){
count+=change;
}else{break;}
change=change/2;
}
xry=(double)count;
}else if(t3<f3){
while(change>1){
count=270;
if(cos(360/M_PI*(double)count)<Lengthofxtoy){
count-=change;
}
else if(cos(360/M_PI*(double)count)>Lengthofxtoy){
count+=change;
}else{break;}
change=change/2;
}
xry=(double)count;
}else {xry=0;}
std::cout<<Lengthofxztoy<<'\n';
std::cout<<cos(360/M_PI*xyrz)<<'\n';
std::cout<<Lengthofxtoy<<'\n';
std::cout<<cos(360/M_PI*xry)<<'\n';
return xyrz*1000+xry;//6桁で出てくるはず・・・
}
int main()
{ double x,y,z,tx,ty,tz,ans;
std::cin>>x;//主点x
std::cin>>y;//主点y
std::cin>>z;//主点z
std::cin>>tx;//対称点x
std::cin>>ty;//対称点y
std::cin>>tz;//対称点z
ans=returnrad(x,y,z,tx,ty,tz);
std::cout<<ans;
std::cin>>ans;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment