#include "StdAfx.h"
#include "CustomMath.h"
CCustomMath::CCustomMath(void)
{
}
CCustomMath::~CCustomMath(void)
{
}
void CCustomMath::GetLinePara(__Line *l)
{
l->a=l->p1.y-l->p2.y;
l->b=l->p2.x-l->p1.x;
l->c=l->p1.x*l->p2.y-l->p2.x*l->p1.y;
}
bool CCustomMath::GetCrossPoint(__Line *l1,__Line *l2,__Point& result)
{
GetLinePara(l1);
GetLinePara(l2);
float D=l1->a*l2->b-l2->a*l1->b;
if(fabs(D) < 0.001)
{
return false;
}
__Point p;
p.x=(l1->b*l2->c-l2->b*l1->c)/D;
p.y=(l1->c*l2->a-l2->c*l1->a)/D;
result = p;
return true;
}