Пример #1
0
void Bullet::moveto(QPoint pos){
	QPoint a = getSpeedVector(), b = pos - getCurPostion();
	double alength = VectorLength(a), blength = VectorLength(b);
	double rad;
	if (VectorCross(a, b) <= 0){
		rad = VectorAngle(a, b) / acos(-1.0) * 180.0;
	}
	else{
		rad = -VectorAngle(a, b) / acos(-1.0) * 180.0;
	}
	a = b * alength / blength;
	setSpeedVector(a);
	lastPos = lastPos + getSpeedVector();
}
Пример #2
0
double CalcSVF(double xs, double ys,double Beta, double TreeHeight, double TreeInterval, double rc){

	struct VecPoint T0,T1,T2,T3;
	struct VecPoint I0,I1,I2,I3;
	struct VecPoint S;

	double Gamma0;
	double Gamma1;
	double Gamma2;
	double Gamma3;
	double svf;

	if((xs==0)&&(ys==0)){
		xs=1e-36;
		ys=1e-36;
	}
	Beta=Beta*Pi180;
	S.x=xs; S.y=ys* cos(Beta); S.z=ys* sin(Beta);//(*Point on the ground*);

	T0.x= 0; T0.y=0;T0.z= 0;//(*Tree 0*)
	T1.x= TreeInterval; T1.y=0;T1.z= 0;//(*Tree 1*)
	T2.x= TreeInterval;T2.y= TreeInterval*cos(Beta);T2.z= TreeInterval *sin(Beta);//(*Tree 2*)
	T3.x=0; T3.y=TreeInterval* cos(Beta); T3.z=TreeInterval* sin(Beta);//(*Tree 3*)

	I0.x =rc *cos(atan(ys *cos(Beta)/xs));
	I0.y =  rc *sin(atan(ys* cos(Beta)/xs));
	I0.z =  TreeHeight;//(*Point on Top of the tree, *)

	I1.x = TreeInterval - rc *cos(atan(ys *cos(Beta)/(TreeInterval- xs)));
	I1.y =  rc *sin(atan(ys* cos(Beta)/(TreeInterval - xs)));
	I1.z =  TreeHeight;

	I2.x = TreeInterval - rc *cos(atan((TreeInterval - ys) *cos(Beta)/(TreeInterval - xs)));
	I2.y = TreeInterval- rc *sin(atan((TreeInterval - ys)* cos(Beta)/(TreeInterval - xs)));
	I2.z = TreeInterval *sin(Beta) + TreeHeight;

	I3.x = rc* cos(atan((TreeInterval - ys) *cos(Beta)/(xs)));
	I3.y =TreeInterval - rc *sin(atan((TreeInterval - ys) *cos(Beta)/(xs)));
	I3.z =TreeInterval *sin(Beta) + TreeHeight;

	Gamma0 = VectorAngle(Vector(S, I0), Vector(T0, S)) - Pi/2;
	Gamma1 = VectorAngle(Vector(S, I1), Vector(T1, S)) - Pi/2;
	Gamma2 = VectorAngle(Vector(S, I2), Vector(T2, S)) - Pi/2;
	Gamma3 = VectorAngle(Vector(S, I3), Vector(T3, S)) - Pi/2;

	svf = (Gamma0 + Gamma1 + Gamma2 + Gamma3)/(2* Pi);

return svf;
}
Пример #3
0
void Bullet::Paint(QPainter * painter, QRect){

	QPoint a(0, -10), b = this->speed;
	double rad;
	if (VectorCross(a, b) <= 0){
		rad = VectorAngle(a, b) / acos(-1.0) * 180.0;
	}
	else{
		rad = -VectorAngle(a, b) / acos(-1.0) * 180.0;
	}

	QPixmap tmpImg = img;
	QTransform transformed;
	transformed.rotate(-rad);
	painter->drawPixmap(getCurPostion() - QPoint(width() / 2, height() / 2), img.transformed(transformed));
}
Пример #4
0
  /* Calculate the angle between point a and the plane determined by b,c,d */
  double Point2PlaneAngle(const Eigen::Vector3d& a, const Eigen::Vector3d& b, 
      const Eigen::Vector3d& c, const Eigen::Vector3d& d)
  {
    Eigen::Vector3d ac, bc, cd, normal;
    double angle;

    ac = a - c;
    bc = b - c;
    cd = c - d;
 
    normal = bc.cross(cd);
    angle = 90.0 - VectorAngle(normal, ac);

    return angle;
  }
Пример #5
0
double SVFNPoints(double xs, double ys,double Beta, double TreeHeight, double TreeInterval, double rc,int N){

	struct VecPoint T[49],I[49],S; 
	double Gamma[49];
	double SVF=0;
	
	if((xs==0)&&(ys==0)){
		xs=1e-36;
		ys=1e-36;
	}

	double TreeIntervalCosBeta=TreeInterval*cos(Beta*Pi180);
	double TreeIntervalSinBeta=TreeInterval*sin(Beta*Pi180);

	S.x=xs;	
	S.y=ys* cos(Beta*Pi180);		
	S.z=ys* sin(Beta*Pi180);				//(*Point on the ground*);
	
	int Counter=0;
	for(int i=-N;i<=N;i++){
		for(int j=-N;j<=N;j++){
			
			T[Counter].x=i*TreeInterval;
			T[Counter].y=j*TreeIntervalCosBeta;
			T[Counter].z=j*TreeIntervalSinBeta;
			
			I[Counter].x=T[Counter].x+rc*(S.x-T[Counter].x)/sqrt((S.x-T[Counter].x)*(S.x-T[Counter].x)+(S.y-T[Counter].y)*(S.y-T[Counter].y));
			I[Counter].y=T[Counter].y+rc*(S.y-T[Counter].y)/sqrt((S.x-T[Counter].x)*(S.x-T[Counter].x)+(S.y-T[Counter].y)*(S.y-T[Counter].y));
			I[Counter].z=T[Counter].z+TreeHeight;

			Gamma[Counter]=Pi/2-VectorAngle(Vector(S, I[Counter]), Vector(S,T[Counter]));
			SVF=SVF+Gamma[Counter]/((2*N+1)*(2*N+1)*Pi/2);
			Counter++;
		}
	}

	SVF=min(max(SVF,0),1);
	return SVF;
}
Пример #6
0
void testVectorAngleTrue21(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(5, 1) - 0.19739555) < eps);
}
Пример #7
0
void testVectorAngleTrue01(CuTest *tc){
    CuAssertTrue(tc, VectorAngle(1, 0) == 0);
}
Пример #8
0
void testVectorAngleTrue10(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(-5, 0) - PI) < eps);
}
Пример #9
0
void testVectorAngleTrue55(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(5, -2) - 5.90267893) < eps);
}
Пример #10
0
void testVectorAngleTrue53(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(5, -4) - 5.60844436) < eps);
}
Пример #11
0
void testVectorAngleTrue51(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(4, -5) - 5.38712992) < eps);
}
Пример #12
0
void testVectorAngleTrue41(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(-5, -3) - 3.68201215) < eps);
}
Пример #13
0
void testVectorAngleTrue40(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(-5, -2) - 3.52209903) < eps);
}
Пример #14
0
void testVectorAngleTrue39(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(-5, -1) - 3.33898821) < eps);
}
Пример #15
0
void testVectorAngleTrue38(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(-5, 1) - 2.94419709) < eps);
}
Пример #16
0
void testVectorAngleTrue49(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(2, -5) - 5.09289535) < eps);
}
Пример #17
0
void testVectorAngleTrue50(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(3, -5) - 5.25280848) < eps);
}
Пример #18
0
void testVectorAngleTrue42(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(-5, -4) - 3.81633359) < eps);
}
Пример #19
0
void testVectorAngleTrue52(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(5, -5) - PI74) < eps);
}
Пример #20
0
void testVectorAngleTrue43(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(-5, -5) - PI54) < eps);
}
Пример #21
0
void testVectorAngleTrue54(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(5, -3) - 5.7427658) < eps);
}
Пример #22
0
void testVectorAngleTrue44(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(-4, -5) - 4.03764803) < eps);
}
Пример #23
0
void testVectorAngleTrue56(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(5, -1) - 6.08578974) < eps);
}
Пример #24
0
void testVectorAngleTrue45(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(-3, -5) - 4.17196948) < eps);
}
Пример #25
0
void testVectorAngleTrue15(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(0, 5) - PIpol) < eps);
}
Пример #26
0
void testVectorAngleTrue46(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(-2, -5) - 4.3318826) < eps);
}
Пример #27
0
void testVectorAngleTrue20(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(0, -5) - PI32) < eps);
}
Пример #28
0
void testVectorAngleTrue47(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(-1, -5) - 4.51499342) < eps);
}
Пример #29
0
void testVectorAngleTrue22(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(5, 2) - 0.38050637) < eps);
}
Пример #30
0
void testVectorAngleTrue48(CuTest *tc){
    CuAssertTrue(tc, abs(VectorAngle(1, -5) - 4.90978454) < eps);
}