Search Results for 'CircumCircle'

ATOM Icon

1 POSTS

  1. 2007/03/23 세점을 지나는 원 구하기 by chungki

세점을 지나는 원 구하기



세점을 지나는 원은 외접원이다. 결국 외접원(CircumCircle)을 구하면 되는 것이다.
원을 구하기 위해서는 중심점과 반지름을 구하면 된다.

Circumcircle


외접원의 중심점은 외심과 같다. 그래서 외심을 구하면 되는 건데 수학적으로 외심은
세변의 수직이등분선이 교차하는 점이다. 문제는 이걸 어떻게 코딩으로 구현하냐는 것이다.

가장 간단한 방법은 중심점으로부터 세 점의 거리가 서로 같다는 식을 세워놓고 연립방정식을 풀면 된다. 두번째 방법으로는 Woflram MathWorld 홈페이지를 참고한다.  두번째 방법으로 하자. ㅎㅎ

다음은 ARmaxSDK 2007에 들어가 있는 기본구조체소스이다.

기본구조체 (Language : cpp)
  1. /// 2차원 점 템플릿 구조체
  2. template <class _TX,int _Type=0>
  3. struct mt_POINT2
  4. {     
  5.     union     
  6.     {         
  7.         struct { _TX x,y; };         
  8.         _TX _m[2];     
  9.     };
  10. }
  11.  
  12. /// 3x3행렬 템플릿 구조체
  13. template <class _tx=mF32>
  14. struct mt_MATRIX9
  15. {     
  16.     union     
  17.     {         
  18.         struct 
  19.         {               
  20.             _tx m11,m12,m13;               
  21.             _tx m21,m22,m23;               
  22.             _tx m31,m32,m33;         
  23.         };         
  24.         _tx _m[9];     
  25.     };
  26. };
  27.  
  28. /// 3x3행렬식 구하기
  29. template <class _tx>
  30. mINLINE _tx mDeterminats(mIN const mt_MATRIX9<_tx>& _mx)
  31. {     
  32.     _tx ret=_mx.m11*_mx.m22*_mx.m33 -  _mx.m11*_mx.m23*_mx.m32-    _mx.m12*_mx.m21*_mx.m33+ _mx.m13*_mx.m21*_mx.m32+          _mx.m12*_mx.m23*_mx.m31- _mx.m13*_mx.m22*_mx.m31;     
  33.     return ret;
  34. }
  35.  
  36. /* @brief 2D 벡터 크기*/
  37. template <class _tx, int _type>
  38. mINLINE _tx mMagnitude(mIN const mt_POINT2<_tx,_type> &p)
  39. {     return (p.x*p.x+p.y*p.y); }
  40.  
  41. /** @brief 두 점간의 거리 */
  42. /** @return float형거리 */
  43. template <class _tx, int _type>
  44. mINLINE mF32 mDistancef(mIN const mt_POINT2<_tx,_type> &p1, mIN const  mt_POINT2<_tx,_type> &p2)
  45. {     
  46.     mF32 Magnitude=mMagnitude(p2-p1);     
  47.     return (mF32)sqrt(Magnitude);
  48. }
 
외접원의 중심 좌표구하기 (Language : cpp)
  1. template <class _tx, int _type>
  2. mINLINE mt_POINT2<_tx,_type> mCircumCenter(mIN const
  3. mt_POINT2<_tx,_type>& p1, mIN const mt_POINT2<_tx,_type>& p2,
  4. mIN const mt_POINT2<_tx,_type>& p3)
  5. {     
  6.     mt_POINT2<_tx,_type> ret;     
  7.     mt_MATRIX9<_tx> mxA={p1.x, p1.y, 1,
  8.                              p2.x, p2.y, 1,
  9.                              p3.x, p3.y, 1};
  10.  
  11.     _tx dA=mDeterminats(mxA);   
  12.     mt_MATRIX9<_tx> mxBx={p1.x*p1.x+p1.y*p1.y, p1.y, 1,
  13.                              p2.x*p2.x+p2.y*p2.y, p2.y, 1,
  14.                              p3.x*p3.x+p3.y*p3.y, p3.y, 1};
  15.     _tx bx=-mDeterminats(mxBx);   
  16.     mt_MATRIX9<_tx> mxBy={p1.x*p1.x+p1.y*p1.y, p1.x, 1,
  17.                              p2.x*p2.x+p2.y*p2.y, p2.x, 1,
  18.                              p3.x*p3.x+p3.y*p3.y, p3.x, 1};     
  19.     _tx by=mDeterminats(mxBy);
  20.     ret.x = -(bx/(2.*dA));   
  21.     ret.y = -(by/(2.*dA));   
  22.     return ret;
  23. }
 
외접원의 반지름 구하기 (Language : cpp)
  1. /// 2D 삼각형(Triangle)의 넓이
  2. template <class _tx, int _type>
  3. mINLINE  mF32 mSemiPerimeterf(mIN const mt_POINT2<_tx,_type>& p1,
  4. mIN const mt_POINT2<_tx,_type>& p2, mIN const mt_POINT2<_tx,_type>& p3)
  5. { 
  6.     // p1=A, p2=B, p3=C   
  7.     mF32 a=mDistancef(p2,p3);   
  8.     mF32 b=mDistancef(p1,p3);   
  9.     mF32 c=mDistancef(p1,p2);   
  10.     return (a+b+c)/2.f;
  11. }
  12.  
  13. /** * @brief 2D 삼각형(Triangle)의 외접원의 반지름 * @return float형 */
  14. template <class _tx, int _type> mINLINE mF32 mOutRadiusf(mIN
  15. const mt_POINT2<_tx,_type>& p1, mIN const mt_POINT2<_tx,_type>&
  16. p2,   mIN const mt_POINT2<_tx,_type>& p3)
  17. {   
  18.     // p1=A, p2=B, p3=C   
  19.     mF32 a=mDistancef(p2,p3);   
  20.     mF32 b=mDistancef(p1,p3);   
  21.     mF32 c=mDistancef(p1,p2);   
  22.     mF32 s=mSemiPerimeterf(p1,p2,p3);   
  23.     mF32 R = (a*b*c)/(4*sqrt(s*(s-a)*(s-b)*(s-c)));         return R;
  24. }

Posted by chungki

2007/03/23 22:20 2007/03/23 22:20
,
Response
No Trackback , No Comment
RSS :
http://www.chungki.net/tc/rss/response/243


블로그 이미지

Nice !!!!!!!!

- chungki

Notices

Archives

Authors

  1. chungki

Calendar

«   2012/05   »
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Site Stats

Total hits:
73375
Today:
6
Yesterday:
20