# Determinant Predicates

When re-reading Real-Time Collision Detection by Christer Ericson i came across a section called Determinant Predicates in Chapter 3 A Math and Geometry Primer. I thought it was interesting that from just filling a matrix with data such a points in space and finding the determinate of that matrix you could do geometrical tests. Although the tests are not the most efficient ways for solving the problems outlined here i just wanted to make an implementation in C++ to test it myself.

The source is hosted on GitHub, you can find that here: Link

In the source i have provided 3 solution’s based on the matrices in the chapter.

1: orient2D which tests is a point (C) is on the left or right of a line defined by AB. The determinate ```Matrix3x3(float aX, float aY,
float bX, float bY,
float cX, float cY)
{
data = aX;	data = aY;	data = 1;
data = bX;	data = bY;	data = 1;
data = cX;	data = cY;	data = 1;
}

float Determinate()
{
return data * ((data * data) - (data * data)) -
data * ((data * data) - (data * data)) +
data * ((data * data) - (data * data));
}
//					 A        B       C
Matrix3x3 orient2D(10,10,	 5,5,	4,15);

cout << "C lies to the left of the directed line AB" << endl;
cout << "C lies to the right of the directed line AB" << endl;
```

2: orient3D which tests is a point (D) above or below the plane define by ABC ```Matrix4x4(float aX, float aY, float aZ,
float bX, float bY, float bZ,
float cX, float cY, float cZ,
float dX, float dY, float dZ)
{
data = aX;	data = aY;	data = aZ;	data = 1;
data = bX;	data = bY;	data = bZ;	data = 1;
data = cX;	data = cY;	data = cZ;	data = 1;
data = dX;	data = dY;	data = dZ;	data = 1;
}

//					 A		  B		  C			D
Matrix4x4 orient3D(1,4,2,	0,1,4,	-1,0,1,	  2,0,4);

cout << "D lies below the supporting plane of triangle ABC" << endl;
cout << "D lies above the supporting plane of triangle ABC" << endl;
```

3: inCircle2D which tests if a point (D) is inside a circle whose points ABC lie on the circumference. ```float InCircle2D(float aX, float aY,
float bX, float bY,
float cX, float cY,
float dX, float dY)
{
float AxAy_Squared = (aX * aX) + (aY * aY);
float BxBy_Squared = (bX * bX) + (bY * bY);
float CxCy_Squared = (cX * cX) + (cY * cY);
float DxDy_Squared = (dX * dX) + (dY * dY);

Matrix4x4 matrix(aX, aY, AxAy_Squared,
bX, bY, BxBy_Squared,
cX, cY, CxCy_Squared,
dX, dY, DxDy_Squared);