Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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
Unity3d 检查一组点是否位于使用每个角的八个点创建的立方体形状内的最佳方法是什么?_Unity3d_Plane - Fatal编程技术网

Unity3d 检查一组点是否位于使用每个角的八个点创建的立方体形状内的最佳方法是什么?

Unity3d 检查一组点是否位于使用每个角的八个点创建的立方体形状内的最佳方法是什么?,unity3d,plane,Unity3d,Plane,检查一组点是否位于使用每个角的八个点创建的立方体形状内的最佳方法是什么 所以,我正在使用这些“平面”进行测试。但这项测试并没有产生完全有效的结果。有些人在,有些人应该在,有些人不在,有些人不应该在 using System; public class Class1 { private struct SelectionPoints { public Vector3 SelectoionPlaneNearTL; public Vector3 Sele

检查一组点是否位于使用每个角的八个点创建的立方体形状内的最佳方法是什么

所以,我正在使用这些“平面”进行测试。但这项测试并没有产生完全有效的结果。有些人在,有些人应该在,有些人不在,有些人不应该在

using System;

public class Class1
{
    private struct SelectionPoints
    {
        public Vector3 SelectoionPlaneNearTL;
        public Vector3 SelectoionPlaneFarTL;

        public Vector3 SelectoionPlaneNearBR;
        public Vector3 SelectoionPlaneFarBR;

        public Vector3 SelectoionPlaneNearTR;
        public Vector3 SelectoionPlaneFarTR;

        public Vector3 SelectoionPlaneNearBL;
        public Vector3 SelectoionPlaneFarBL;
    }

    private void methodName(Vector3 pos)
    {
        SelectionPoints _selectionPoints;

        //...
        //code to fill in _selectionPoints
        //...

        Plane planeTop = new Plane(_selectionPoints.SelectoionPlaneFarTR,_selectionPoints.SelectoionPlaneFarTL,_selectionPoints.SelectoionPlaneNearTL);
        Plane planeRight = new Plane(_selectionPoints.SelectoionPlaneFarBR,_selectionPoints.SelectoionPlaneNearTR,selectionPoints.SelectoionPlaneFarTR);
        Plane planeBottom = new Plane(selectionPoints.SelectoionPlaneFarBL,_selectionPoints.SelectoionPlaneNearBR,_selectionPoints.SelectoionPlaneFarBR);
        Plane planeLeft = new Plane(_selectionPoints.SelectoionPlaneFarBL,_selectionPoints.SelectoionPlaneNearTL,_selectionPoints.SelectoionPlaneFarTL);
        Plane planeNear = new Plane(_selectionPoints.SelectoionPlaneNearBR,_selectionPoints.SelectoionPlaneNearTR,_selectionPoints.SelectoionPlaneNearTL);
        Plane planeFar = new Plane(selectionPoints.SelectoionPlaneFarTL,_selectionPoints.SelectoionPlaneFarTR,_selectionPoints.SelectoionPlaneFarBR);

        if (
            (planeTop.GetSide(point)) &&
            (planeBottom.GetSide(point)) &&
            (planeRight.GetSide(point)) &&
            (planeLeft.GetSide(point)) &&
            (planeNear.GetSide(point)) &&
            (planeFar.GetSide(point))
            )
        {
            return true;
        }
    }
}

在Unity3d中,平面是一个无限大的平面,存在于3D空间中,将空间分成两半,称为半空间。您可以使用
GetSide()
确定特定点位于两个半空间中的哪一个,以及该点离平面的距离

此外,平面也可以由平面内三角形的三个角点定义。在这种情况下,当您查看上的三角形面时,如果角点沿顺时针方向旋转,则法向量指向您

首先,我假设您的代码中有一个输入错误,您在检查过程中使用的向量3被称为
,但您的输入作为函数被称为
pos

但是这里的主要问题是
planeRight
防御,应该是这样的:

Plane planeRight = new Plane(_selectionPoints.SelectoionPlaneFarBR,selectionPoints.SelectoionPlaneFarTR,_selectionPoints.SelectoionPlaneNearTR);  
在这种形式下,法向量将处于正确的位置


希望这能解决您的问题。

在Unity3d中,平面是一个无限大的平面,存在于3D空间中,并将空间分成两部分,称为半空间,您可以使用
GetSide()
确定特定点位于两部分空间中的哪一部分,以及该点离平面的距离

此外,平面也可以由平面内三角形的三个角点定义。在这种情况下,当您查看
上的三角形面时,如果角点沿顺时针方向旋转,则法向量指向您

首先,我假设您的代码中有一个输入错误,您在检查过程中使用的向量3被称为
,但您的输入作为函数被称为
pos

但是这里的主要问题是
planeRight
防御,应该是这样的:

Plane planeRight = new Plane(_selectionPoints.SelectoionPlaneFarBR,selectionPoints.SelectoionPlaneFarTR,_selectionPoints.SelectoionPlaneNearTR);  
在这种形式下,法向量将处于正确的位置


希望这能解决您的问题。

您想从我们这里得到什么??我现在很困惑|对不起,这不是它的要点。我想我要问的是检查我的代码,看看一组点是否在由八个点定义的形状内。好的,现在我明白你的问题了。你想从我们这里得到什么??我现在很困惑|对不起,这不是它的要点。我想我要问的是检查我的代码,看看一组点是否在由八个点定义的形状内。好了,现在我明白你的问题了。