如何获得虚拟平面的 4 个顶点坐标? [英] How can I get 4 vertices's coordinate of the virtual plane?

查看:22
本文介绍了如何获得虚拟平面的 4 个顶点坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过Scenekit基于真实表制作了虚拟平面(SCNPlane).另外,我想知道虚拟平面的4个顶点的坐标.

I made the virtual plane (SCNPlane) based on real table through Scenekit. Additionally, I want to know 4 vertices's coordinate of the virtual plane.

点击此处查看图片.

推荐答案

可以得到边界框的坐标,就像 BlackMirrorz 说.

You can get the coordinates of the bounding box, just as BlackMirrorz said.

let (min, max) = planeNode.boundingBox

这将为您提供作为 SCNVector3 对象的对角(最小和最大).这些坐标将相对于对象,未旋转、未平移和未缩放.导出二维平面中的另外两个角坐标.不用担心 Z 轴.SCNPlane 本质上是一个 2D 对象.

This will give you opposite corners (min and max) as SCNVector3 objects. Those coordinates will be relative to the object, unrotated, untranslated, and unscaled. Derive the other two corner coordinates in the 2d plane. Don't worry about the Z axis. An SCNPlane is fundamentally a 2D object.

let bottomLeft = SCNVector3(min.x, min.y, 0)
let topRight = SCNVector3(max.x, max.y, 0)

let topLeft = SCNVector3(min.x, max.y, 0)
let bottomRight = SCNVector3(max.x, min.y, 0)

然后调用

let worldBottomLeft = planeNode.convertPosition(bottomLeft, to: rootNode)
let worldTopRight = planeNode.convertPosition(topRight, to: rootNode)

let worldTopLeft = planeNode.convertPosition(topLeft, to: rootNode)
let worldBottomRight = planeNode.convertPosition(bottomRight, to: rootNode)

将每个坐标转换为世界空间.系统会为您进行旋转、平移和缩放.

to convert each coordinate to world space. The system will do the rotation, translation, and scaling for you.

这篇关于如何获得虚拟平面的 4 个顶点坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆