コード例 #1
0
ファイル: unitcommon.cpp プロジェクト: 702nADOS/speed-dreams
//==========================================================================*
// Utility to normalize a 2D vector
//--------------------------------------------------------------------------*
TVec2d TUtils::VecUnit( const TVec2d& v )
{
	double	h = myhypot(v.x, v.y);
	if( h == 0 )
		return TVec2d(0, 0);
	else
		return TVec2d(v.x / h, v.y / h);
}
コード例 #2
0
//==========================================================================*
// perpendicular distance measure.
//--------------------------------------------------------------------------*
void TLinearRegression::CalcLine(TVec2d& Point, TVec2d& V) const
{
  Point = TVec2d(oSumX / oCount, oSumY / oCount);

  // a = x - p.x, b = y - p.y
  double SumAA = oSumXX - 2 * Point.x * oSumX + oCount * Point.x * Point.x;
  double SumBB = oSumYY - 2 * Point.y * oSumY + oCount * Point.y * Point.y;
  double SumAB = oSumXY
	- Point.y * oSumX - Point.x * oSumY + oCount * Point.x * Point.y;

  double Angle = atan2(2 * SumAB, SumAA - SumBB) / 2;
  V = TVec2d(cos(Angle), sin(Angle));
}
コード例 #3
0
ファイル: unitcommon.cpp プロジェクト: 702nADOS/speed-dreams
//==========================================================================*
// Utility to normalize a 2D vector
//--------------------------------------------------------------------------*
TVec2d TUtils::VecNorm( const TVec2d& v )
{
	return TVec2d(-v.y, v.x);
}