Skip to content

Instantly share code, notes, and snippets.

@mactkg
Forked from anonymous/rad of2point.cpp
Created April 16, 2011 18:10
Show Gist options
  • Save mactkg/923363 to your computer and use it in GitHub Desktop.
Save mactkg/923363 to your computer and use it in GitHub Desktop.
#include <math.h>
#define _USE_MATH_DEFINES
#include <iostream>
double LengthCos(double t1,t2,t3,f1,f2,f3) {
return sqrt(((t1-f1)*(t1-f1)+(t3-f3)*(t3-f3)))/sqrt(((t1-f1)*(t1-f1)+(t2-f2)*(t2-f2)+(t3-f3)*(t3-f3)));
}
double LengthDegree(double t1,t3,f1,f3) {
return sqrt((t1-f1)*(t1-f1))/sqrt(((t1-f1)*(t1-f1)+(t3-f3)*(t3-f3)));
}
double returnrad(double f1,double f2,double f3,double t1,double t2,double t3){
int count,change=45;
double xyrz,xry,xz_y,x_y;
xz_y=LengthCos(t1,t2,t3,f1,f2,f3);//xz平面に対するcos
x_y=LengthDegree(t1,t3,f1,f3);//xとzの角度
if(t2>f2){//以下二分木による探索
count=90;
while(change>1){
if(cos((double)count)<xz_y){
count+=change;
}else if(cos((double)count)>xz_y){
count-=change;
}
else{break;}
change=change/2;
}
xyrz=(double)count;
}else if(t2<f2){
count=270;
while(change>1){
if(cos((double)count)<xz_y){
count-=change;
}else if(cos((double)count)>xz_y){
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((double)count)<x_y){
count-=change;
}
else if(cos((double)count)>x_y){
count+=change;
}else{break;}
change=change/2;
}
xry=(double)count;
}else if(t3<f3){
while(change>1){
count=270;
if(cos((double)count)<x_y){
count+=change;
}
else if(cos((double)count)>x_y){
count-=change;
}else{break;}
change=change/2;
}
xry=(double)count;
}else {xry=0;}
std::cout<<xz_y<<'\n';
std::cout<<cos(xyrz)<<'\n';
std::cout<<x_y<<'\n';
std::cout<<cos(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