proj home

Files   Classes   Functions   Hierarchy  

solverInconsistent< T > Class Template Reference

Solve 1D and 2D linear equations with one move variable than the number of equations. More...

#include <mathlib.h>

List of all members.

Static Public Member Functions

static boolc d1linearequ (T &x, T &y, T const a0, T const a1, T const c)
 Find a solution for the equation a0*x+a1*y=c.
static boolc d2linearequ (T &x, T &y, T &z, T const a00, T const a01, T const a02, T const c0, T const a10, T const a11, T const a12, T const c1)
 Find a solution for the equations { a00*x+a01*y=c0, a10*x+a11*y=c1 }.


Detailed Description

template<typename T>
class solverInconsistent< T >

Solve 1D and 2D linear equations with one move variable than the number of equations.

Find a point that satisfies the equations.

For example plane to plane intersection gives two equations in three unknowns.

Definition at line 161 of file mathlib.h.


Member Function Documentation

template<typename T >
boolc solverInconsistent< T >::d1linearequ ( T x,
T y,
T const   a0,
T const   a1,
T const   c 
) [inline, static]

Find a solution for the equation a0*x+a1*y=c.

Definition at line 1021 of file mathlib.h.

01028 {
01029   if (zero<T>::test(a0))
01030   {
01031     x = 0;
01032     if (zero<T>::test(a1))
01033     {
01034       y = 0;
01035       return (c==0);
01036     }
01037     y = c/a1;
01038     return true;
01039   }
01040 
01041   if (zero<T>::test(a1))
01042   {
01043     y = 0;
01044     x = c/a0;
01045     return true;
01046   }
01047 
01048   x=1.0;
01049   y = (c-a0)/a1;
01050   return true;
01051 }

template<typename T >
boolc solverInconsistent< T >::d2linearequ ( T x,
T y,
T z,
T const   a00,
T const   a01,
T const   a02,
T const   c0,
T const   a10,
T const   a11,
T const   a12,
T const   c1 
) [inline, static]

Find a solution for the equations { a00*x+a01*y=c0, a10*x+a11*y=c1 }.

Definition at line 1056 of file mathlib.h.

References solver< T >::d2linearequ().

Referenced by plane::intersects().

01069 {
01070   if (zero<T>::test(a00))
01071   {
01072     if (zero<T>::test(a10))
01073     {
01074       x=0;
01075       return solver<T>::d2linearequ(y,z,a01,a02,a10,a11,c0,c1);
01076     }
01077 
01078     return d2linearequ(x,y,z,a10,a11,a12,c1,a00,a01,a02,c0);
01079   }
01080 
01081   T e[3];
01082   e[0] = a11-a10*a01/a00; 
01083   e[1] = a12-a10*a02/a00;
01084   e[2] = c1-a10*c0/a00;
01085 
01086   bool res = d1linearequ(y,z,e[0],e[1],e[2]);
01087   if (res==false)
01088     return false;
01089 
01090   x = (c0-a01*y-a02*z)/a00;
01091 
01092   return true;
01093 }


The documentation for this class was generated from the following file:

Generated on Fri Mar 4 00:50:18 2011 for Chelton Evans Source by  doxygen 1.5.8