c·c++/c++ 프로그래밍

삼각형의 외심 구하기

바로이순간 2012. 8. 23. 14:35

#include <iostream> 

using namespace std; 

double Ax, Ay, Bx, By, Cx, Cy; 

double MidSideAx, MidSideAy, MidSideCx, MidSideCy; 

double SlopeAB, SlopeBC, CircumCenterX, CircumCenterY;  

double GetCircumCenterXY() { 

   MidSideAx = ((Bx + Cx)/2.0); 

   MidSideAy = ((By + Cy)/2.0); 

   MidSideCx = ((Bx + Ax)/2.0); 

   MidSideCy = ((By + Ay)/2.0); 

   //Inverted Slopes of two Perpendicular lines of the Triangle 

   SlopeAB =-((Bx - Ax)/(By - Ay)); 

   SlopeBC =-((Cx - Bx)/(Cy - Ay)); 

   CircumCenterX = ((SlopeBC * MidSideAx) + MidSideAy - (SlopeAB * MidSideCx) + MidSideCy) / (SlopeBC - SlopeAB); 

   CircumCenterY = SlopeAB * (CircumCenterX - MidSideCx) + MidSideCy; 

   return (((SlopeBC * MidSideAx) + MidSideAy) - ((SlopeAB * MidSideCx) + MidSideCy)) / (SlopeBC - SlopeAB); 

//These integers are inputted by the User earlier in the code via cin 

int main() { 

   cout<<"Ax, Ay = "; cin>>Ax>>Ay;  

   cout<<"Bx, By = "; cin>>Bx>>By; 

   cout<<"Cx, Cy = "; cin>>Cx>>Cy; 

   GetCircumCenterXY(); 

   cout<<"CircumCenterX, Y = "<<CircumCenterX<<" "<<CircumCenterY<<endl; 

   return 0; 



입력할 때는 분모가 0이 되지 않게 주의해야 합니다.