proj home

Files   Classes   Functions   Hierarchy  

circleLine Class Reference

Circle and line intersection test. More...

#include <mathlib.h>

List of all members.

Static Public Member Functions

template<typename PT , typename PD >
static boolc intersection2D (PT &p0, PT &p1, PD const radius, PT const &q0, PT const &q1)
 Find the intersection of the line with points q0 and q1 with the circle at the origin.


Detailed Description

Circle and line intersection test.

Definition at line 583 of file mathlib.h.


Member Function Documentation

template<typename PT , typename PD >
boolc circleLine::intersection2D ( PT &  p0,
PT &  p1,
PD const   radius,
PT const &  q0,
PT const &  q1 
) [inline, static]

Find the intersection of the line with points q0 and q1 with the circle at the origin.

Assumes that the points are 2D.

Definition at line 610 of file mathlib.h.

References solvequadratic().

Referenced by disk::intersects(), and mathlibtest::test015().

00617 {
00618   assert( zero<PD>::test( (q0-q1).dot()) == false );
00619 
00620   // Hard coded type. No templated solvequadratic.
00621 
00622   PT B(q1-q0);
00623 
00624   doublec a = B.dot();
00625   doublec b = q0.dot(B)*2.0;
00626   doublec c = q0.dot()-radius*radius;
00627   double t0;
00628   double t1;
00629   bool res;
00630   res = solvequadratic(t0,t1,a,b,c);
00631   if (res==false)
00632     return false;
00633 
00634   p0 = q0 + B*t0;
00635   p1 = q0 + B*t1;
00636 
00637   return true;
00638 }


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

Generated on Fri Mar 4 00:49:52 2011 for Chelton Evans Source by  doxygen 1.5.8