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(); }
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; }
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)); }
/* 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; }
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; }
void testVectorAngleTrue21(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(5, 1) - 0.19739555) < eps); }
void testVectorAngleTrue01(CuTest *tc){ CuAssertTrue(tc, VectorAngle(1, 0) == 0); }
void testVectorAngleTrue10(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(-5, 0) - PI) < eps); }
void testVectorAngleTrue55(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(5, -2) - 5.90267893) < eps); }
void testVectorAngleTrue53(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(5, -4) - 5.60844436) < eps); }
void testVectorAngleTrue51(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(4, -5) - 5.38712992) < eps); }
void testVectorAngleTrue41(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(-5, -3) - 3.68201215) < eps); }
void testVectorAngleTrue40(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(-5, -2) - 3.52209903) < eps); }
void testVectorAngleTrue39(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(-5, -1) - 3.33898821) < eps); }
void testVectorAngleTrue38(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(-5, 1) - 2.94419709) < eps); }
void testVectorAngleTrue49(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(2, -5) - 5.09289535) < eps); }
void testVectorAngleTrue50(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(3, -5) - 5.25280848) < eps); }
void testVectorAngleTrue42(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(-5, -4) - 3.81633359) < eps); }
void testVectorAngleTrue52(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(5, -5) - PI74) < eps); }
void testVectorAngleTrue43(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(-5, -5) - PI54) < eps); }
void testVectorAngleTrue54(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(5, -3) - 5.7427658) < eps); }
void testVectorAngleTrue44(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(-4, -5) - 4.03764803) < eps); }
void testVectorAngleTrue56(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(5, -1) - 6.08578974) < eps); }
void testVectorAngleTrue45(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(-3, -5) - 4.17196948) < eps); }
void testVectorAngleTrue15(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(0, 5) - PIpol) < eps); }
void testVectorAngleTrue46(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(-2, -5) - 4.3318826) < eps); }
void testVectorAngleTrue20(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(0, -5) - PI32) < eps); }
void testVectorAngleTrue47(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(-1, -5) - 4.51499342) < eps); }
void testVectorAngleTrue22(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(5, 2) - 0.38050637) < eps); }
void testVectorAngleTrue48(CuTest *tc){ CuAssertTrue(tc, abs(VectorAngle(1, -5) - 4.90978454) < eps); }