Example #1
0
tCircleParams PhysicsRecord::getCircleParams(const Hit & p1, const Hit & p2, const Hit & p3) const{

	tCircleParams params;

	//circle fit
	//map points to parabloid: (x,y) -> (x,y,x^2+y^2)
	fVector3 pP1 (p1.globalX(),
			p1.globalY(),
			p1.globalX() * p1.globalX() + p1.globalY() * p1.globalY());

	fVector3 pP2 (p2.globalX(),
			p2.globalY(),
			p2.globalX() * p2.globalX() + p2.globalY() * p2.globalY());

	fVector3 pP3 (p3.globalX(),
			p3.globalY(),
			p3.globalX() * p3.globalX() + p3.globalY() * p3.globalY());

	//span two vectors
	fVector3 a(pP2.x - pP1.x, pP2.y - pP1.y, pP2.z - pP1.z);
	fVector3 b(pP3.x - pP1.x, pP3.y - pP1.y, pP3.z - pP1.z);

	//compute unit cross product
	fVector3 n(a.y*b.z - a.z*b.y,
			a.z*b.x - a.x*b.z,
			a.x*b.y - a.y*b.x );
	double value = sqrt(n.x*n.x+n.y*n.y+n.z*n.z);
	n.x /= value; n.y /= value; n.z /= value;

	//formula for orign and radius of circle from Strandlie et al.
	params.center = fVector2((-n.x) / (2*n.z),
			(-n.y) / (2*n.z));

	double c = -(n.x*pP1.x + n.y*pP1.y + n.z*pP1.z);

	params.radius = sqrt((1 - n.z*n.z - 4 * c * n.z) / (4*n.z*n.z));

	return params;
}