使用三点系统计算模型中的压痕深度? [英] Calculate depth of indentation in an model using three point system?

查看:111
本文介绍了使用三点系统计算模型中的压痕深度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过光线投射可以选择GameObjects Collider上的一个点.在短视觉中,用小球体表示三个点,表示用户选择.期望计算模型压痕中任何斑点的深度.当前的想法是使用一种系统,在该系统中,用户选择压痕深度以外的两个点和压痕深度内的一个点,然后计算压痕深度.

Via Raycasting one can select a point on an GameObjects Collider. In the short visual three points are represented with small spheres denoting user selection. The desire is to calculate the depth of any spot in an models indentation. Current thought is to use a system in which the user selects two points outside the depth and a point within the depth of the indentation than calculate the indentations depth.

可供我们使用的信息是空间中的三个点(向量),它们与使用三个点的任何其他向量数学之间的距离.我们如何使用上述数据计算压痕深度?计算与深度中的点垂直的点是否可行且合理?认为如果该点比深度可计算,则为那两个点之间的距离.如何解决这个问题,是否可行,是否有更好的方法?

The information available to us is the three points (Vectors) in space, the distance between them and any other Vector math utilizing three points. How do we use the aforementioned data to calculate the depth of our indentation? Is it feasible and a reasonable approach to calculate a point perpendicular to the point in the depth? Thought being if this point is calculable than the depth would be the distance between those two points. How to go about this, is it feasible, is there perhaps a better approach?

推荐答案

这是一个非常开放的问题,因为简单的深度"非常模糊.如果您可以在世界空间中找到模型上的一些点,可以使用以下两种方法:

This is a pretty open question because simply "depth" is pretty vague. Here are two approaches if you can find some points on the model in world space:

  1. 让用户单击他们想知道其深度"的点.

  1. Have the user click on the point whose "depth" they want to know.

RaycastHit indentHit;
Vector3 depthPoint = indentHit.point;

  • 让用户单击缩进"之外的三个点.这三个点定义了一个平面,我们将用它作为深度"测量的参考.

  • Have the user click on three points outside of the "indentation". These three points define a plane that we are going to use as a reference for our "depth" measurement.

    RaycastHit hitA;
    RaycastHit hitB;
    RaycastHit hitC;
    
    Vector3 a = hitA.point;
    Vector3 b = hitB.point;
    Vector3 c = hitC.point; 
    
    Plane surfacePlane = new Plane(a, b, c); 
    

  • 使用Plane.GetDistanceToPoint查找点到平面的距离.我们不在乎方向,仅在乎距离,因此我们使用Mathf.Abs来确保距离为正值:

  • Find the distance of the point from the plane using Plane.GetDistanceToPoint. We don't care about the direction, just the distance, so we use Mathf.Abs to make sure our distance is positive:

    float depth = Mathf.Abs(surfacePlane.GetDistanceToPoint(depthPoint));
    

  • 方法2:从曲面上的1个点及其法线创建参考平面.

    另一种方法是,在模型表面上获取一个点,在压痕上获取一个点,然后在模型表面上的单个点之外创建一个平面,并使用其法线来创建一个平面从这一点出发:

    Method 2: Create reference plane from 1 point on surface and its normal.

    Another way you can do it is by taking one point on the surface of the model and one point on the indentation, and creating a plane out of the single point on the surface of the model and using its normal to create a plane from that one point:

    1. 让用户单击他们想知道其深度"的点.

    1. Have the user click on the point whose "depth" they want to know.

    RaycastHit indentHit;
    Vector3 depthPoint = indentHit.point;
    

  • 让用户单击缩进"之外的一个点.然后,在该点找到法线.通过这些,您可以生成一个平面.

  • Have the user click on one point outside of the "indentation". Then, find the normal at that point. From these, you can generate a plane.

    RaycastHit surfaceHit;
    Vector3 surfacePoint = surfaceHit.point;
    Vector3 surfaceNormal = surfaceHit.normal;
    
    Plane surfacePlane = new Plane(surfaceNormal.normalized, surfacePoint);
    

    可能值得尝试的事情是允许获取多个点和法线并将它们取平均值以创建平面. 如果尝试此操作,只需确保获得普通的normalized形式.

    Something that might be worth trying is allowing for taking multiple points and normals and averaging them out to create the plane. If you try this, just make sure that you get the normalized form of the normal.

    使用Plane.GetDistanceToPoint查找点到平面的距离.我们不在乎方向,仅在乎距离,因此我们使用Mathf.Abs来确保距离为正值:

    Find the distance of the point from the plane using Plane.GetDistanceToPoint. We don't care about the direction, just the distance, so we use Mathf.Abs to make sure our distance is positive:

    float depth = Mathf.Abs(surfacePlane.GetDistanceToPoint(depthPoint));
    

  • 这篇关于使用三点系统计算模型中的压痕深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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