00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00055 #include "Geometry.h"
00056 #include <stdio.h>
00057
00062 int sign( double d1 )
00063 {
00064 return (d1>0)?1:-1;
00065 }
00066
00071 double max( double d1, double d2 )
00072 {
00073 return (d1>d2)?d1:d2;
00074 }
00075
00080 double min( double d1, double d2 )
00081 {
00082 return (d1<d2)?d1:d2;
00083 }
00084
00085
00090 AngDeg Rad2Deg( AngRad x )
00091 {
00092 return ( x * 180 / M_PI );
00093 }
00094
00099 AngRad Deg2Rad( AngDeg x )
00100 {
00101 return ( x * M_PI / 180 );
00102 }
00103
00108 double cosDeg( AngDeg x )
00109 {
00110 return ( cos( Deg2Rad( x ) ) );
00111 }
00112
00117 double sinDeg( AngDeg x )
00118 {
00119 return ( sin( Deg2Rad( x ) ) );
00120 }
00121
00126 double tanDeg( AngDeg x )
00127 {
00128 return ( tan( Deg2Rad( x ) ) );
00129 }
00130
00136 AngDeg atanDeg( double x )
00137 {
00138 return ( Rad2Deg( atan( x ) ) );
00139 }
00140
00149 double atan2Deg( double x, double y )
00150 {
00151 if( fabs( x ) < EPSILON && fabs( y ) < EPSILON )
00152 return ( 0.0 );
00153
00154 return ( Rad2Deg( atan2( x, y ) ) );
00155 }
00156
00161 AngDeg acosDeg( double x )
00162 {
00163 if( x >= 1 )
00164 return ( 0.0 );
00165 else if( x <= -1 )
00166 return ( 180.0 );
00167
00168 return ( Rad2Deg( acos( x ) ) );
00169 }
00170
00175 AngDeg asinDeg( double x )
00176 {
00177 if( x >= 1 )
00178 return ( 90.0 );
00179 else if ( x <= -1 )
00180 return ( -90.0 );
00181
00182 return ( Rad2Deg( asin( x ) ) );
00183 }
00184
00193 bool isAngInInterval( AngDeg ang, AngDeg angMin, AngDeg angMax )
00194 {
00195
00196 if( ( ang + 360 ) < 360 ) ang += 360;
00197 if( ( angMin + 360 ) < 360 ) angMin += 360;
00198 if( ( angMax + 360 ) < 360 ) angMax += 360;
00199
00200 if( angMin < angMax )
00201 return angMin < ang && ang < angMax ;
00202 else
00203 return !( angMax < ang && ang < angMin );
00204 }
00205
00212 AngDeg getBisectorTwoAngles( AngDeg angMin, AngDeg angMax )
00213 {
00214
00215 return VecPosition::normalizeAngle(
00216 atan2Deg( (sinDeg( angMin) + sinDeg( angMax ) )/2.0,
00217 (cosDeg( angMin) + cosDeg( angMax ) )/2.0 ) );
00218 }
00219
00220
00221
00222
00223
00238 VecPosition::VecPosition( double x, double y, CoordSystemT cs )
00239 {
00240 setVecPosition( x, y, cs );
00241 }
00242
00247 VecPosition VecPosition::operator - ( )
00248 {
00249 return ( VecPosition( -m_x, -m_y ) );
00250 }
00251
00260 VecPosition VecPosition::operator + ( const double &d )
00261 {
00262 return ( VecPosition( m_x + d, m_y + d ) );
00263 }
00264
00270 VecPosition VecPosition::operator + ( const VecPosition &p )
00271 {
00272 return ( VecPosition( m_x + p.m_x, m_y + p.m_y ) );
00273 }
00274
00283 VecPosition VecPosition::operator - ( const double &d )
00284 {
00285 return ( VecPosition( m_x - d, m_y - d ) );
00286 }
00287
00296 VecPosition VecPosition::operator - ( const VecPosition &p )
00297 {
00298 return ( VecPosition( m_x - p.m_x, m_y - p.m_y ) );
00299 }
00300
00308 VecPosition VecPosition::operator * ( const double &d )
00309 {
00310 return ( VecPosition( m_x * d, m_y * d ) );
00311 }
00312
00320 VecPosition VecPosition::operator * ( const VecPosition &p )
00321 {
00322 return ( VecPosition( m_x * p.m_x, m_y * p.m_y ) );
00323 }
00324
00333 VecPosition VecPosition::operator / ( const double &d )
00334 {
00335 return ( VecPosition( m_x / d, m_y / d ) );
00336 }
00337
00345 VecPosition VecPosition::operator / ( const VecPosition &p )
00346 {
00347 return ( VecPosition( m_x / p.m_x, m_y / p.m_y ) );
00348 }
00349
00355 void VecPosition::operator = ( const double &d )
00356 {
00357 m_x = d;
00358 m_y = d;
00359 }
00360
00366 void VecPosition::operator +=( const VecPosition &p )
00367 {
00368 m_x += p.m_x;
00369 m_y += p.m_y;
00370 }
00371
00378 void VecPosition::operator += ( const double &d )
00379 {
00380 m_x += d;
00381 m_y += d;
00382 }
00383
00391 void VecPosition::operator -=( const VecPosition &p )
00392 {
00393 m_x -= p.m_x;
00394 m_y -= p.m_y;
00395 }
00396
00404 void VecPosition::operator -=( const double &d )
00405 {
00406 m_x -= d;
00407 m_y -= d;
00408 }
00409
00417 void VecPosition::operator *=( const VecPosition &p )
00418 {
00419 m_x *= p.m_x;
00420 m_y *= p.m_y;
00421 }
00422
00430 void VecPosition::operator *=( const double &d )
00431 {
00432 m_x *= d;
00433 m_y *= d;
00434 }
00435
00442 void VecPosition::operator /=( const VecPosition &p )
00443 {
00444 m_x /= p.m_x;
00445 m_y /= p.m_y;
00446 }
00447
00455 void VecPosition::operator /=( const double &d )
00456 {
00457 m_x /= d;
00458 m_y /= d;
00459 }
00460
00468 bool VecPosition::operator !=( const VecPosition &p )
00469 {
00470 return ( ( m_x != p.m_x ) || ( m_y != p.m_y ) );
00471 }
00472
00482 bool VecPosition::operator !=( const double &d )
00483 {
00484 return ( ( m_x != d ) || ( m_y != d ) );
00485 }
00486
00495 bool VecPosition::operator ==( const VecPosition &p )
00496 {
00497 return ( ( m_x == p.m_x ) && ( m_y == p.m_y ) );
00498 }
00499
00509 bool VecPosition::operator ==( const double &d )
00510 {
00511 return ( ( m_x == d ) && ( m_y == d ) );
00512 }
00513
00522 ostream& operator <<( ostream &os, VecPosition v )
00523 {
00524 return ( os << "( " << v.m_x << ", " << v.m_y << " )" );
00525 }
00526
00532 void VecPosition::show( CoordSystemT cs )
00533 {
00534 if( cs == CARTESIAN )
00535 cout << *this << endl;
00536 else
00537 cout << "( r: " << getMagnitude( ) << ", phi: " << getDirection( ) << " )";
00538 }
00539
00547 string VecPosition::str( CoordSystemT cs )
00548 {
00549 char buf[ 1024 ];
00550
00551 if( cs == CARTESIAN )
00552 sprintf( buf, "( %f, %f )", getX( ), getY( ) );
00553 else
00554 sprintf( buf, "( r: %f, phi: %f )", getMagnitude( ), getDirection( ) );
00555
00556 string str( buf );
00557 return ( str );
00558 }
00559
00564 bool VecPosition::setX( double dX )
00565 {
00566 m_x = dX;
00567 return ( true );
00568 }
00569
00573 double VecPosition::getX( ) const
00574 {
00575 return ( m_x );
00576 }
00577
00582 bool VecPosition::setY( double dY )
00583 {
00584 m_y = dY;
00585 return ( true );
00586 }
00587
00591 double VecPosition::getY( ) const
00592 {
00593 return ( m_y );
00594 }
00595
00611 void VecPosition::setVecPosition( double dX, double dY, CoordSystemT cs)
00612 {
00613 if( cs == CARTESIAN )
00614 {
00615 m_x = dX;
00616 m_y = dY;
00617 }
00618 else
00619 *this = getVecPositionFromPolar( dX, dY );
00620 }
00621
00630 double VecPosition::getDistanceTo( const VecPosition p )
00631 {
00632 return ( ( *this - p ).getMagnitude( ) );
00633 }
00634
00647 VecPosition VecPosition::setMagnitude( double d )
00648 {
00649 if( getMagnitude( ) > EPSILON )
00650 ( *this ) *= ( d / getMagnitude( ) );
00651
00652 return ( *this );
00653 }
00654
00661 double VecPosition::getMagnitude( ) const
00662 {
00663 return ( sqrt( m_x * m_x + m_y * m_y ) );
00664 }
00665
00674 AngDeg VecPosition::getDirection( ) const
00675 {
00676 return ( atan2Deg( m_y, m_x ) );
00677 }
00678
00687 bool VecPosition::isInFrontOf( const VecPosition &p )
00688 {
00689 return ( ( m_x > p.getX( ) ) ? true : false );
00690 }
00691
00701 bool VecPosition::isInFrontOf( const double &d )
00702 {
00703 return ( ( m_x > d ) ? true : false );
00704 }
00705
00716 bool VecPosition::isBehindOf( const VecPosition &p )
00717 {
00718 return ( ( m_x < p.getX( ) ) ? true : false );
00719 }
00720
00729 bool VecPosition::isBehindOf( const double &d )
00730 {
00731 return ( ( m_x < d ) ? true : false );
00732 }
00733
00744 bool VecPosition::isLeftOf( const VecPosition &p )
00745 {
00746 return ( ( m_y < p.getY( ) ) ? true : false );
00747 }
00748
00758 bool VecPosition::isLeftOf( const double &d )
00759 {
00760 return ( ( m_y < d ) ? true : false );
00761 }
00762
00773 bool VecPosition::isRightOf( const VecPosition &p )
00774 {
00775 return ( ( m_y > p.getY( ) ) ? true : false );
00776 }
00777
00787 bool VecPosition::isRightOf( const double &d )
00788 {
00789 return ( ( m_y > d ) ? true : false );
00790 }
00791
00806 bool VecPosition::isBetweenX( const VecPosition &p1, const VecPosition &p2 )
00807 {
00808 return ( ( isInFrontOf( p1 ) && isBehindOf( p2 ) ) ? true : false );
00809 }
00810
00824 bool VecPosition::isBetweenX( const double &d1, const double &d2 )
00825 {
00826 return ( ( isInFrontOf( d1 ) && isBehindOf( d2 ) ) ? true : false );
00827 }
00828
00843 bool VecPosition::isBetweenY( const VecPosition &p1, const VecPosition &p2 )
00844 {
00845 return ( ( isRightOf( p1 ) && isLeftOf( p2 ) ) ? true : false );
00846 }
00847
00861 bool VecPosition::isBetweenY( const double &d1, const double &d2 )
00862 {
00863 return ( ( isRightOf( d1 ) && isLeftOf( d2 ) ) ? true : false );
00864 }
00865
00872 VecPosition VecPosition::normalize( )
00873 {
00874 return ( setMagnitude( 1.0 ) );
00875 }
00876
00891 VecPosition VecPosition::rotate( AngDeg angle )
00892 {
00893
00894 double dMag = this->getMagnitude( );
00895 double dNewDir = this->getDirection( ) + angle;
00896 setVecPosition( dMag, dNewDir, POLAR );
00897 return ( *this );
00898 }
00899
00917 VecPosition VecPosition::globalToRelative( VecPosition origin, AngDeg ang )
00918 {
00919
00920
00921
00922
00923
00924 *this -= origin;
00925 return ( rotate( -ang ) );
00926 }
00927
00943 VecPosition VecPosition::relativeToGlobal( VecPosition origin, AngDeg ang )
00944 {
00945
00946
00947
00948
00949
00950 rotate( ang );
00951 *this += origin;
00952 return ( *this );
00953 }
00954
00969 VecPosition VecPosition::getVecPositionOnLineFraction( VecPosition &p,
00970 double dFrac )
00971 {
00972
00973
00974
00975
00976 return ( ( *this ) * ( 1.0 - dFrac ) + ( p * dFrac ) );
00977 }
00978
00991 VecPosition VecPosition::getVecPositionFromPolar( double dMag, AngDeg ang )
00992 {
00993
00994 return ( VecPosition( dMag * cosDeg( ang ), dMag * sinDeg( ang ) ) );
00995 }
00996
01003 AngDeg VecPosition::normalizeAngle( AngDeg angle )
01004 {
01005 while( angle > 180.0 ) angle -= 360.0;
01006 while( angle < -180.0 ) angle += 360.0;
01007
01008 return ( angle );
01009 }
01010
01011
01012
01013
01014
01015
01026 double Geometry::getLengthGeomSeries( double dFirst, double dRatio, double dSum )
01027 {
01028 if( dRatio < 0 )
01029 cerr << "(Geometry:getLengthGeomSeries): negative ratio" << endl;
01030
01031
01032
01033
01034 double temp = (dSum * ( dRatio - 1 ) / dFirst) + 1;
01035 if( temp <= 0 )
01036 return -1.0;
01037 return log( temp ) / log( dRatio ) ;
01038 }
01039
01050 double Geometry::getSumGeomSeries( double dFirst, double dRatio, double dLength)
01051 {
01052
01053
01054 return dFirst * ( 1 - pow( dRatio, dLength ) ) / ( 1 - dRatio ) ;
01055 }
01056
01067 double Geometry::getSumInfGeomSeries( double dFirst, double dRatio )
01068 {
01069 if( dRatio > 1 )
01070 cerr << "(Geometry:CalcLengthGeomSeries): series does not converge" <<endl;
01071
01072
01073 return dFirst / ( 1 - dRatio );
01074 }
01075
01086 double Geometry::getFirstGeomSeries( double dSum, double dRatio, double dLength)
01087 {
01088
01089
01090 return dSum * ( 1 - dRatio )/( 1 - pow( dRatio, dLength ) ) ;
01091 }
01092
01103 double Geometry::getFirstInfGeomSeries( double dSum, double dRatio )
01104 {
01105 if( dRatio > 1 )
01106 cerr << "(Geometry:getFirstInfGeomSeries):series does not converge" <<endl;
01107
01108
01109 return dSum * ( 1 - dRatio );
01110 }
01111
01121 int Geometry::abcFormula(double a, double b, double c, double *s1, double *s2)
01122 {
01123 double dDiscr = b*b - 4*a*c;
01124 if (fabs(dDiscr) < EPSILON )
01125 {
01126 *s1 = -b / (2 * a);
01127 return 1;
01128 }
01129 else if (dDiscr < 0)
01130 return 0;
01131 else
01132 {
01133 dDiscr = sqrt(dDiscr);
01134 *s1 = (-b + dDiscr ) / (2 * a);
01135 *s2 = (-b - dDiscr ) / (2 * a);
01136 return 2;
01137 }
01138 }
01139
01140
01141
01142
01143
01148 Circle::Circle( VecPosition pos, double dR )
01149 {
01150 setCircle( pos, dR );
01151 }
01152
01155 Circle::Circle( )
01156 {
01157 setCircle( VecPosition(-1000.0,-1000.0), 0);
01158 }
01159
01164 void Circle::show( ostream& os)
01165 {
01166 os << "c:" << m_posCenter << ", r:" << m_dRadius;
01167 }
01168
01174 bool Circle::setCircle( VecPosition pos, double dR )
01175 {
01176 setCenter( pos );
01177 return setRadius( dR );
01178 }
01182 bool Circle::setRadius( double dR )
01183 {
01184 if( dR > 0 )
01185 {
01186 m_dRadius = dR;
01187 return true;
01188 }
01189 else
01190 {
01191 m_dRadius = 0.0;
01192 return false;
01193 }
01194 }
01195
01198 double Circle::getRadius()
01199 {
01200 return m_dRadius;
01201 }
01202
01206 bool Circle::setCenter( VecPosition pos )
01207 {
01208 m_posCenter = pos;
01209 return true;
01210 }
01211
01214 VecPosition Circle::getCenter()
01215 {
01216 return m_posCenter;
01217 }
01218
01221 double Circle::getCircumference()
01222 {
01223 return 2.0*M_PI*getRadius();
01224 }
01225
01228 double Circle::getArea()
01229 {
01230 return M_PI*getRadius()*getRadius();
01231 }
01232
01240 bool Circle::isInside( VecPosition pos )
01241 {
01242 return m_posCenter.getDistanceTo( pos ) < getRadius() ;
01243 }
01244
01251 int Circle::getIntersectionPoints( Circle c, VecPosition *p1, VecPosition *p2)
01252 {
01253 double x0, y0, r0;
01254 double x1, y1, r1;
01255
01256 x0 = getCenter( ).getX();
01257 y0 = getCenter( ).getY();
01258 r0 = getRadius( );
01259 x1 = c.getCenter( ).getX();
01260 y1 = c.getCenter( ).getY();
01261 r1 = c.getRadius( );
01262
01263 double d, dx, dy, h, a, x, y, p2_x, p2_y;
01264
01265
01266 dx = x1 - x0;
01267 dy = y1 - y0;
01268 d = sqrt(dx*dx + dy*dy);
01269
01270
01271 dx /= d; dy /= d;
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281 a = (r0*r0 + d*d - r1*r1) / (2.0 * d);
01282
01283
01284 double arg = r0*r0 - a*a;
01285 h = (arg > 0.0) ? sqrt(arg) : 0.0;
01286
01287
01288 p2_x = x0 + a * dx;
01289 p2_y = y0 + a * dy;
01290
01291
01292 x = p2_x - h * dy;
01293 y = p2_y + h * dx;
01294 p1->setVecPosition( x, y );
01295 x = p2_x + h * dy;
01296 y = p2_y - h * dx;
01297 p2->setVecPosition( x, y );
01298
01299 return (arg < 0.0) ? 0 : ((arg == 0.0 ) ? 1 : 2);
01300 }
01301
01305 double Circle::getIntersectionArea( Circle c )
01306 {
01307 VecPosition pos1, pos2, pos3;
01308 double d, h, dArea;
01309 AngDeg ang;
01310
01311 d = getCenter().getDistanceTo( c.getCenter() );
01312 if( d > c.getRadius() + getRadius() )
01313 return 0.0;
01314 if( d <= fabs(c.getRadius() - getRadius() ) )
01315 {
01316 double dR = min( c.getRadius(), getRadius() );
01317 return M_PI*dR*dR;
01318 }
01319
01320 int iNrSol = getIntersectionPoints( c, &pos1, &pos2 );
01321 if( iNrSol != 2 )
01322 return 0.0;
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337 pos3 = pos1.getVecPositionOnLineFraction( pos2, 0.5 );
01338 d = pos1.getDistanceTo( pos3 );
01339 h = pos3.getDistanceTo( getCenter() );
01340 ang = asin( d / getRadius() );
01341
01342 dArea = ang*getRadius()*getRadius();
01343 dArea = dArea - d*h;
01344
01345
01346 h = pos3.getDistanceTo( c.getCenter() );
01347 ang = asin( d / c.getRadius() );
01348 dArea = dArea + ang*c.getRadius()*c.getRadius();
01349 dArea = dArea - d*h;
01350
01351 return dArea;
01352 }
01353
01354
01355
01356
01357
01358
01364 Line::Line( double dA, double dB, double dC )
01365 {
01366 m_a = dA;
01367 m_b = dB;
01368 m_c = dC;
01369 }
01370
01376 ostream& operator <<(ostream & os, Line l)
01377 {
01378 double a = l.getACoefficient();
01379 double b = l.getBCoefficient();
01380 double c = l.getCCoefficient();
01381
01382
01383 if( a == 0 )
01384 os << "x = " << -c/b;
01385 else
01386 {
01387 os << "y = ";
01388 if( b != 0 )
01389 os << -b/a << "x ";
01390 if( c > 0 )
01391 os << "- " << fabs(c/a);
01392 else if( c < 0 )
01393 os << "+ " << fabs(c/a);
01394 }
01395 return os;
01396 }
01397
01400 void Line::show( ostream& os)
01401 {
01402 os << *this;
01403 }
01404
01409 VecPosition Line::getIntersection( Line line )
01410 {
01411 VecPosition pos;
01412 double x, y;
01413 if( ( m_a / m_b ) == (line.getACoefficient() / line.getBCoefficient() ))
01414 return pos;
01415 if( m_a == 0 )
01416 {
01417 x = -m_c/m_b;
01418 y = line.getYGivenX(x);
01419 }
01420 else if( line.getACoefficient() == 0 )
01421 {
01422 x = -line.getCCoefficient()/line.getBCoefficient();
01423 y = getYGivenX(x);
01424 }
01425
01426
01427
01428
01429
01430 else
01431 {
01432 x = (m_a*line.getCCoefficient() - line.getACoefficient()*m_c)/
01433 (line.getACoefficient()*m_b - m_a*line.getBCoefficient());
01434 y = getYGivenX(x);
01435 }
01436
01437 return VecPosition( x, y );
01438 }
01439
01440
01448 int Line::getCircleIntersectionPoints( Circle circle,
01449 VecPosition *posSolution1, VecPosition *posSolution2 )
01450 {
01451 int iSol;
01452 double dSol1=0, dSol2=0;
01453 double h = circle.getCenter().getX();
01454 double k = circle.getCenter().getY();
01455
01456
01457
01458
01459
01460
01461 if( fabs(m_a) < EPSILON )
01462 {
01463 iSol = Geometry::abcFormula( 1, -2*k, ((-m_c/m_b) - h)*((-m_c/m_b) - h)
01464 + k*k - circle.getRadius()*circle.getRadius(), &dSol1, &dSol2);
01465 posSolution1->setVecPosition( (-m_c/m_b), dSol1 );
01466 posSolution2->setVecPosition( (-m_c/m_b), dSol2 );
01467 return iSol;
01468 }
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478 double da = -m_b/m_a;
01479 double db = -m_c/m_a;
01480
01481 double dA = 1 + da*da;
01482 double dB = 2*( da*db - h - k*da );
01483 double dC = h*h + db*db-2*k*db + k*k - circle.getRadius()*circle.getRadius();
01484
01485 iSol = Geometry::abcFormula( dA, dB, dC, &dSol1, &dSol2 );
01486
01487 posSolution1->setVecPosition( dSol1, da*dSol1 + db );
01488 posSolution2->setVecPosition( dSol2, da*dSol2 + db );
01489 return iSol;
01490
01491 }
01492
01498 Line Line::getTangentLine( VecPosition pos )
01499 {
01500
01501
01502
01503 return Line( m_b, -m_a, m_a*pos.getX() - m_b*pos.getY() );
01504 }
01505
01509 VecPosition Line::getPointOnLineClosestTo( VecPosition pos )
01510 {
01511 Line l2 = getTangentLine( pos );
01512 return getIntersection( l2 );
01513 }
01514
01519 double Line::getDistanceWithPoint( VecPosition pos )
01520 {
01521 return pos.getDistanceTo( getPointOnLineClosestTo( pos ) );
01522 }
01523
01532 bool Line::isInBetween( VecPosition pos, VecPosition point1,VecPosition point2)
01533 {
01534 pos = getPointOnLineClosestTo( pos );
01535 double dDist = point1.getDistanceTo( point2 );
01536
01537
01538
01539 return pos.getDistanceTo( point1 ) <= dDist &&
01540 pos.getDistanceTo( point2 ) <= dDist;
01541 }
01542
01546 double Line::getYGivenX( double x )
01547 {
01548 if( m_a == 0 )
01549 {
01550 cerr << "(Line::getYGivenX) Cannot calculate Y coordinate: " ;
01551 show( cerr );
01552 cerr << endl;
01553 return 0;
01554 }
01555
01556 return -(m_b*x+m_c)/m_a;
01557 }
01558
01562 double Line::getXGivenY( double y )
01563 {
01564 if( m_b == 0 )
01565 {
01566 cerr << "(Line::getXGivenY) Cannot calculate X coordinate\n" ;
01567 return 0;
01568 }
01569
01570 return -(m_a*y+m_c)/m_b;
01571 }
01572
01577 Line Line::makeLineFromTwoPoints( VecPosition pos1, VecPosition pos2 )
01578 {
01579
01580
01581
01582 double dA, dB, dC;
01583 double dTemp = pos2.getX() - pos1.getX();
01584 if( fabs(dTemp) < EPSILON )
01585 {
01586
01587 dA = 0.0;
01588 dB = 1.0;
01589 }
01590 else
01591 {
01592
01593 dA = 1.0;
01594 dB = -(pos2.getY() - pos1.getY())/dTemp;
01595 }
01596
01597 dC = - dA*pos2.getY() - dB * pos2.getX();
01598 return Line( dA, dB, dC );
01599 }
01600
01605 Line Line::makeLineFromPositionAndAngle( VecPosition vec, AngDeg angle )
01606 {
01607
01608
01609 return makeLineFromTwoPoints( vec, vec+VecPosition(1,angle,POLAR));
01610 }
01611
01614 double Line::getACoefficient() const
01615 {
01616 return m_a;
01617 }
01618
01621 double Line::getBCoefficient() const
01622 {
01623 return m_b;
01624 }
01625
01628 double Line::getCCoefficient() const
01629 {
01630 return m_c;
01631 }
01632
01633
01634
01635
01636
01643 Rect::Rect( VecPosition pos, VecPosition pos2 )
01644 {
01645 setRectanglePoints( pos, pos2 );
01646 }
01647
01652 void Rect::setRectanglePoints( VecPosition pos1, VecPosition pos2 )
01653 {
01654 m_posLeftTop.setX ( max( pos1.getX(), pos2.getX() ) );
01655 m_posLeftTop.setY ( min( pos1.getY(), pos2.getY() ) );
01656 m_posRightBottom.setX( min( pos1.getX(), pos2.getX() ) );
01657 m_posRightBottom.setY( max( pos1.getY(), pos2.getY() ) );
01658 }
01659
01663 void Rect::show( ostream& os )
01664 {
01665 os << "rect(" << m_posLeftTop << " " << m_posRightBottom << ")";
01666 }
01667
01672 bool Rect::isInside( VecPosition pos )
01673 {
01674 return pos.isBetweenX( m_posRightBottom.getX(), m_posLeftTop.getX() ) &&
01675 pos.isBetweenY( m_posLeftTop.getY(), m_posRightBottom.getY() );
01676
01677 }
01678
01682 bool Rect::setPosLeftTop( VecPosition pos )
01683 {
01684 m_posLeftTop = pos;
01685 return true;
01686 }
01687
01690 VecPosition Rect::getPosLeftTop( )
01691 {
01692 return m_posLeftTop;
01693 }
01694
01698 bool Rect::setPosRightBottom( VecPosition pos )
01699 {
01700 m_posRightBottom = pos;
01701 return true;
01702 }
01703
01706 VecPosition Rect::getPosRightBottom( )
01707 {
01708 return m_posRightBottom;
01709 }
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780