简体   繁体   English

如何从位置和地标获取(X,Y)向量

[英]How to get (X,Y) vectors from position and landmark

I currently have an agent in a map, whose position is known as myPos=(myX,myY) , but whose orientation myOri=(oriX,oriY) is unknown. 我当前在地图中有一个代理,其位置称为myPos=(myX,myY) ,但其方向myOri=(oriX,oriY)未知。 I also see a landmark at position lm=(lmX,lmY) and I have both Cartesian and polar coordinates from my point of view to the landmark, as relLM=(relX,relY) and polLM=(r,theta) , respectively. 我还在位置lm=(lmX,lmY)看到了一个界标,从我的角度到该界标,我同时具有笛卡尔坐标和极坐标,分别为relLM=(relX,relY)polLM=(r,theta)

My goal is to find how my orientation vector is related with the X and Y axis, as XX=(xX, xY) and YY=(yX, yY) . 我的目标是找到我的方向向量与X和Y轴的关系,如XX=(xX, xY)YY=(yX, yY) Assume for the following examples that X grows to the right and Y grows upwards, and that an agent with 0 rotation follows the X axis (so an agent looking right has XX=(1,0) and YY=(0,1) . This follows from the intuition where 0 angle rotation is on the X axis, PI/2 rotation is on the Y, PI is on -X, 3PI/2 is on -Y and 2PI is X. 对于以下示例,假设X向右生长,Y向上方生长,并且旋转0的代理沿X轴移动(因此,向右看的代理具有XX=(1,0)YY=(0,1)这是根据直觉得出的,其中0角度旋转在X轴上,PI / 2旋转在Y上,PI在-X上,3PI / 2在-Y上,而2PI是X。

Example) If myOri=(1,1) (agent is facing top right), then XX=(1, -1) (since the X axis is top right to him) and YY=(1, 1) (the Y axis is top left). 示例)如果myOri=(1,1) (座席朝右上),则XX=(1, -1) (因为X轴在他的右上角)和YY=(1, 1) (Y轴在左上方)。 In the picture below, X and Y are shown in red and green. 在下图中,X和Y以红色和绿色显示。 My agent is in blue and the landmark in pink. 我的经纪人是蓝色,地标是粉红色。 Hence, our initial data are myPos=(0,-2) , lm=(0,-1) , relLM=(~0.7,~0.7) . 因此,我们的初始数据是myPos=(0,-2)lm=(0,-1)relLM=(~0.7,~0.7)relLM=(~0.7,~0.7)

范例图片

By knowing myPos and lmPos , as well as relLM , this should be possible. 通过了解myPoslmPos以及relLM ,这应该是可能的。 However, I'm having trouble finding the appropriate vectors. 但是,我很难找到合适的向量。 What is the correct algorithm? 什么是正确的算法?

bool someFunction(Landmark *lm, Vector2f myPos, Vector2f *xx, Vector2f *yy){
    // Vector from agent to landmark
    Vector2f agentToLandmark(lm->position.x - myPos.x,
            lm->position.y - myPos.y);

    // Vector from agent to landmark, regarding agent's orientation
    Vector2f agentFacingLandmark = lm->relPosition.toCartesian();        

    // Set the XX and YY values
    // how?
}

My problem is actually in 3D, but using 2D makes the problem easier to explain. 我的问题实际上是在3D中,但是使用2D使问题更易于解释。

Finding myOri 寻找myOri

Since relLM is lm relative to myOri , lm + relLM must be in myPos + µ * myOri . 由于relLMlm相对于myOrilm + relLM必须在myPos + µ * myOri Thus lm + relLM - myPos = myOri * µ . 因此, lm + relLM - myPos = myOri * µ Since µ > 0 must be given in this case, and myOri only needs to indicate a direction, it's sufficient to choose an arbitrary µ > 0 . 由于在这种情况下必须给出µ > 0 ,并且myOri只需要指示方向,因此选择任意µ > 0就足够了。

Finding xx and yy 查找xx和yy

I think your definition of xx is simply a vector representing the x-axis from the POV of the agent. 我认为您对xx的定义只是一个向量,它代表了来自代理POV的x轴。 And same for yy and the y-axis. yy和y轴也一样。 This can easily be achieved. 这很容易实现。 The angle between myOri and the x-axis is equal to the angle between the x-axis and xx , thus simply mirror myOri at the x-axis and you got xx . myOri与x轴之间的角度等于x轴与xx之间的角度,因此只需在x轴上镜像myOri即可得到xx So xx = (myOri.x , myOri.y * (-1)) . 所以xx = (myOri.x , myOri.y * (-1)) The angle between myOri and the y-axis is equal to the angle between myOri and yy , so yy = myOri . myOri和y轴之间的角度等于myOriyy之间的角度,因此yy = myOri

Note that this is only a guess on what you mean. 请注意,这仅是对您的意思的猜测。
Might be that I've misunderstood something. 可能是因为我误会了一些东西。 Just notify me if that's the case. 如果是这样,请通知我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM