vector.cpp

来自「本程序是2005年参加中国机器人大赛的比赛程序」· C++ 代码 · 共 67 行

CPP
67
字号
// Vector.cpp: implementation of the Vector class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Robocup.h"
#include "Vector.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Vector::~Vector()
{

}

Vector Vector::Rotate(double ang)
{ 
	ang *= 0.01745329222; 
	return Vector(cos(ang)*x - sin(ang)*y,sin(ang)*x + cos(ang)*y); 
}
double Vector::GetAngle()//返回-180到180之间的角
{
	double k;
	k = atan2(y, x);
	return 57.29578049*k; 
}

BOOL Vector::LineFromTwoPoint(double &A, double &B, double &C, Vector p2)
{
	if(((*this).x-p2.x)*((*this).y-p2.y))
		return FALSE;
	else
	{
		if(!((*this).x-p2.x))
		{
			A=1;B=0;C=0;
		}
		else
		{
			A=(*this).y-p2.y;
			B=(*this).x-p2.x;
			C=(*this).y*p2.x+p2.y*(*this).x;
		}
	}
	return TRUE;
}

BOOL Vector::NearRobot()//判定该点是否靠近任何机器人
{
	for(int i=0; i<4; i++)
	{
		Vector d1(this->x-g_MyTeam[i].Get_vPos().x,this->y-g_MyTeam[i].Get_vPos().y);
		Vector d2(this->x-g_TheirTeam[i].Get_vPos().x,this->y-g_TheirTeam[i].Get_vPos().y);
		if( d1.mod()<LENGTH)		return TRUE;
		if( d2.mod()<LENGTH)		return TRUE;
	}
	return FALSE;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?