简体   繁体   English

如何将现实世界中的3d坐标统一绘制为平面图的2d坐标?

[英]How to plot 3d coordinates in the real world into 2d coordinates of a floor plan in unity?

I am working on a AR app using ARkit.I want to track the user.I can push the x,y and z coordinates of the user.How to map 3d points of the user location in real world into 2d floor plan.There are certain challenges because when the app is opened the user position(camera position) is x,y ,z=(0,0,0).The user position is the camera position.With respect to this how to map in the 2d floor plan.So that when the user moves around, his position can be shown in the 2D-Floor Plan. 我正在使用ARkit开发AR应用程序。我想跟踪用户。我可以按用户的x,y和z坐标。如何将现实世界中用户位置的3d点映射到2d平面图中。某些挑战是因为打开应用程序时用户位置(摄像机位置)是x,y,z =(0,0,0)。用户位置是摄像机位置。关于此在2d平面图中的映射因此,当用户四处移动时,他的位置可以显示在2D楼层平面图中。

I could add AR models and find the distance between them and the user.Will that help to find the coordinates of the user?When I turn the device the coordinates changes so we cant rely on user position(camera position) for plotting. 我可以添加AR模型并找到它们与用户之间的距离,这将有助于找到用户的坐标吗?当我转动设备时,坐标会发生变化,因此我们不能依靠用户位置(相机位置)进行绘图。

private Vector3 Campos;
public GameObject chagepos; //Added as a child of camera
private void LateUpdate()
{




//Created a starting point

Campos.x = 246f;//x-Coordinate of the floor plan
Campos.z = 121f;//y-Coordinate of the floor plan
chagepos.transform.position = new Vector3(Campos.x, 0, Campos.z);

Debug.Log(chagepos.transform.position);
}

在此处输入图片说明

If the user position is represented as a Vector3, then you can just extract the x and z components to get your Vector2: 如果用户位置用Vector3表示,则只需提取x和z分量即可获得Vector2:

Vector2 floorPlanPosition = new Vector2(playerPosition.x, playerPosition.z);

You might need to reproject the floorPlanPosition into the local space of the floor plan object (since that is presumably a 3d object as well) 您可能需要将floorPlanPosition重新投影到平面图对象的本地空间中(因为这大概也是3d对象)

Vector3 worldSpacePositionOfPlayerOnFloorplan = floorPlan.transform.TransformPoint(new Vector3(floorPlanPosition.x, 0, floorPlanPosition.y);

There are other transformations that you might need to do, ie if the player is not at 0,0 within the floorplan, you may need to do some subtraction of offset positions. 您可能还需要执行其他转换,即,如果播放器不在平面图中,则可能需要减去一些偏移位置。

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

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