Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 十、 Y轴斜线如何向上/向下/侧面移动_C_Geometry_Pawn - Fatal编程技术网

C 十、 Y轴斜线如何向上/向下/侧面移动

C 十、 Y轴斜线如何向上/向下/侧面移动,c,geometry,pawn,C,Geometry,Pawn,我有两分,一个起始位置和一个目标位置(动态)。我想像在一级方程式比赛中一样培养球员。i、 第二个在第一个的右边和后面,第三个在第二个的左边和后面,依此类推。我已经确定了他们面对球门的角度 我不知道如何相对于轴线移动。我想我的距离会把它移到一边,但我不是100%肯定。。我也太笨了,不知道如何去垂直于新的点,即使它可能只是在某处加一个负号 好的,我希望有人能帮我,谢谢你 注意:代码在Pawn中,一种类似C的脚本语言 new x1 = RaceCheckpoints[0][0]//startp

我有两分,一个起始位置和一个目标位置(动态)。我想像在一级方程式比赛中一样培养球员。i、 第二个在第一个的右边和后面,第三个在第二个的左边和后面,依此类推。我已经确定了他们面对球门的角度

我不知道如何相对于轴线移动。我想我的距离会把它移到一边,但我不是100%肯定。。我也太笨了,不知道如何去垂直于新的点,即使它可能只是在某处加一个负号

好的,我希望有人能帮我,谢谢你

注意:代码在Pawn中,一种类似C的脚本语言

    new x1 = RaceCheckpoints[0][0]//startpoint x
    new y1 = RaceCheckpoints[0][1]//startpoint y
    new x2 = RaceCheckpoints[1][0]//goalpoint x
    new y2 = RaceCheckpoints[1][1]//goalpoint y
    new dist = 2;
    new pos = 0;
    new x3, y3, x4, y4, a, b, norm;
    x3 = (x1 + x2) / 2;
    y3 = (y1 + y2) / 2;
    a = y1 - y2;
    b = x2 - x1;
    norm = sqrt(a*a + b*b);
    a = a / norm;
    b = b / norm;
    x3 = x3 + a * -dist;
    y3 = y3 + b * -dist;
    x4 = x3 + a * 2 * dist;
    y4 = y3 + b * 2 * dist;
    for(new i;i<MAX_PLAYERS;i++)
    {
        if(RaceParticipant[i] != 0)
        {
            if(IsPlayerInAnyVehicle(i)) PlayerVehicles[i]=GetPlayerVehicleID(i);
            else PlayerVehicles[i]=0;
            if (pos = 0)//left lane
            {
            SetPlayerPosFindZ(playerid, x3, y3, RaceCheckpoints[0][2]+10);
            new angle = atan2(y2 - x3, x2 - y3) * 180 / PI;
            SetPlayerFacingAngle(i,angle);
            pos++;
            }

            if (pos = 1)//right lane
            {
            SetPlayerPosFindZ(playerid, x4, y4, RaceCheckpoints[0][2]+10);
            new angle = atan2(y2 - x4, x2 - y4) * 180 / PI;
            SetPlayerFacingAngle(i,angle);
            pos--;
            }

        }
    }
newx1=RaceCheckpoints[0][0]//起始点x
新y1=比赛检查点[0][1]//起点y
新x2=比赛检查点[1][0]//目标点x
新y2=比赛检查点[1][1]//目标点y
新距离=2;
新位置=0;
新x3、y3、x4、y4、a、b、标准;
x3=(x1+x2)/2;
y3=(y1+y2)/2;
a=y1-y2;
b=x2-x1;
标准=sqrt(a*a+b*b);
a=a/正常值;
b=b/标准;
x3=x3+a*-距离;
y3=y3+b*-距离;
x4=x3+a*2*dist;
y4=y3+b*2*dist;

对于(新i;i让我们假设您的目标直接位于x方向。起点和目标之间的向量是(0,1),它与x轴之间的角度当然是零。我们还假设每辆车有一行
ix
和一列
iy
,第一辆车有行和列0

任何一辆车到第一辆车的距离是

xx = - ix * dx - iy * dd;
yy =  - iy * dy;
其中,
dx
dy
dd
是车辆之间的度量:

    --------000-------------------
     |      000                dd
     |      000        111--------
     dx     000        111
     |      000        111
     |                 111
     |                 111
    --------222
            222
            222        333
            222        333
            222        333
            |          333
            |          333
            |          |
            |--- dy ---|
现在假设你的目标位于其他地方,起点和目标之间的向量是(
vx
vy
)。该向量和x轴之间的角度是
a
。你必须旋转
xx
yy

xx' = cos(a) * xx - sin(a) * yy
yy' = sin(a) * xx + cos(a) * yy
您也可以用矩阵表示法编写:

{P'} = [C] * {P}
其中,
{p}
{p'}
是未旋转和旋转的点,
[C]
是旋转矩阵:

      |  cos(a)     - sin(a)  |
[C] = |                       |
      |  sin(a)       cos(a)  |
你的角度是

a = atan2(vy, vx)
但这里并不需要角度。如果你将vor向量(
vx
vy
)归一化,使其成为单位向量,
vx
vy
已经是你旋转的余弦和正弦

最后一步是将起点添加到旋转位置。将所有这些放在一起(在C中,不是典当):

double dx=8.0;//x第一辆车和第三辆车之间的距离
双dy=5.0;//第一节和第二节车厢之间的y距离
double dd=1.5;//x第一辆车和第二辆车之间的距离
双sx=118.0;//起点,即第一节车厢的位置
双sy=6.0;
双gx=240.0;//目标点
双gy=60.0;
int ncar=8;//车辆数量
double vx=gx-sx;//开始和目标之间的向量
双vy=gy-sy;
双vv;
double acos;//之间的角度的正弦和余弦
双asin;//(vx,vy)和(1,0)
双cx[ncar];//轿厢位置
双cy[ncar];
int i;
vv=sqrt(vx*vx+vy*vy);//归一化向量
acos=vx/vv;//确定旋转余弦
asin=vy/vv;
对于(i=0;i
如果(pos==0
),您的条件应为…`-单等号是一个赋值,双等号是一个比较。赋值计算为赋值,零被视为假,其他一切都被视为真。因此,
pos=0
始终为假,
pos=1
始终为真。还要注意,在第一个分支中增加
pos
,以便它将为1,然后测试它是否为1,这将令人惊讶地为真。第二个块应该以
else
开始,而不是以另一个条件开始。使用
atan2
计算角度也有点可疑:分子应该都是y坐标,分母都是x坐标。你的混合n匹配方法将不适用不要产生预期的结果。(想想如果你把所有东西都向x方向移动一个单位会发生什么。)你是对的。我知道双等号,谢谢你在第二个语句中的输入,我会改变它。至于atan2,我昨天没有真正理解它。现在我已经研究了它,看看它应该是什么样子。你所有的答案都非常清楚。谢谢你所有的答案和更正。
double dx = 8.0;        // x distance between 1st and 3rd car
double dy = 5.0;        // y distance between 1st and 2nd car
double dd = 1.5;        // x distance between 1st and 2nd car

double sx = 118.0;      // start point, i.e. position of 1st car
double sy = 6.0;

double gx = 240.0;      // goal point
double gy = 60.0;

int ncar = 8;           // number of cars

double vx = gx - sx;    // vector between start and goal
double vy = gy - sy;
double vv;

double acos;            // sine and cosine of the angle between
double asin;            // (vx, vy) and (1, 0)

double cx[ncar];        // car positions
double cy[ncar];

int i;

vv = sqrt(vx*vx + vy * vy);             // normalise vector
acos = vx / vv;                         // determine rotation cosines
asin = vy / vv; 

for (i = 0; i < ncar; i++) {
    int ix = i / 2;                     // grid index row
    int iy = i % 2;                     // grid index column

    double xx = - ix * dx - iy * dd;    // unrotated car pos,
    double yy =  - iy * dy;             // 1st car a (0, 0)

    cx[i] = sx + acos * xx - asin * yy;
    cy[i] = sy + asin * xx + acos * yy;
}