home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Conic Sections 0.9.2 / Sources / EquNew.cpp < prev    next >
Encoding:
Text File  |  1997-06-21  |  1.6 KB  |  66 lines  |  [TEXT/CWIE]

  1. //Copyright (c) 1997 Aidan Cully
  2. //All rights reserved
  3.  
  4. #include "EquNew.h"
  5. #include <math.h>
  6. #include "CLStrStuff.h"
  7. #include "Misc.h"
  8. #include "LMath.h"
  9.  
  10. TEquNew::TEquNew( TLayoutBranch *super, MActionHandler *superHandler, Boolean hasDD,
  11.  TPlane *nplane, TConic *conic ):
  12.     TDocContent( super, hasDD, superHandler, nplane )
  13. {
  14.     mConic= conic;
  15. }
  16.  
  17. SInt8 TEquNew::DXDivY( int x, int y, unsigned char *num, unsigned char *den )
  18. {
  19.     MoveTo( x, y );
  20.     DrawString( num );
  21.     MoveTo( x, y+3 );
  22.     Line( 60, 0 );
  23.     MoveTo( x, y+12+6 );
  24.     DrawString( den );
  25. }
  26.  
  27. void TEquNew::DrawSelf( TDrawSlate *gr )
  28. {
  29.     EraseRect( &GetLocalRect() );
  30.     float a,b,npang;
  31.     int dec,sign,deccount;
  32.     Str32 astr,bstr,cstr,ystr;
  33.  
  34.     MoveTo(20,20);
  35.     npang = fmod(mPlane->GetAngle(),180);
  36.     if (fabs(npang)<0.001) {
  37.         a = mPlane->GetDistance()*mPlane->GetDistance();
  38.         StrCpy( astr, gcvt(a,5) );
  39.         DrawString("\px^2 + y^2 =");
  40.         DrawString(astr);
  41.     } else if ((npang == 45) || (npang == 135)) {
  42.         a = 4*mPlane->GetDistance()/2;
  43.         if( npang == 135 )
  44.             a = -a;
  45.         DrawString("\px^2 = ");
  46.         StrCpy( astr, gcvt( a, 5 ) );
  47.         DrawString(astr);
  48.         DrawString("\py");
  49.     } else if ((npang < 45) || (npang > 135)) {
  50.     } else {
  51.         a = mPlane->GetDistance()/mPlane->GetSinAngle();
  52.         a = a*a;
  53.         b = mPlane->GetDistance()*tan((45-mPlane->GetAngle())*M_PI/180);
  54.         b += (mPlane->GetDistance()*tan((45+mPlane->GetAngle())*M_PI/180));
  55.         b /= 2;
  56.         b = b*b;
  57.         StrCpy( astr, gcvt( a, 5 ) );
  58.         DXDivY( 20, 20, "\py^2", astr );
  59.         StrCpy( bstr, gcvt( b, 5 ) );
  60.         DXDivY( 100, 20, "\px^2", bstr );
  61.         MoveTo( 90, 28 );
  62.         DrawString( "\p-" );
  63.         Move(74,0);
  64.         DrawString("\p= 1");
  65.     }
  66. }