简体   繁体   English

如何在python中找到曲面和直线之间的交点?

[英]How to find an intersection between a surface and a line in python?

I have a surface which is defined by a list of x and y values with height assigned to them. 我有一个由x和y值列表定义的表面,并为其分配了高度。 The continuous surface is built with spline methods so in the end I have the heights of all possible (x,y). 连续曲面是用样条方法构建的,因此最终我具有所有可能的高度(x,y)。 I also have a point and unit vector (derived from that point). 我也有一个点和单位向量(从那个点派生)。 What I need is to find the point where the line (made from that unit vector) hits my surface. 我需要找到的点(由该单位矢量制成)撞击我的表面。 I am having trouble with constructing that line (and I am not sure if that is necessary) and finding the fastest way to get the intersection. 我在构建那条线时遇到了麻烦(我不确定是否有必要),并找到最快的方法来获得交叉点。 Thak you for your help. 感谢您的帮助。

EDIT 编辑

This is the example of my coordinates and the code that I was advised to write in order to have my surface. 这是我的坐标和被建议编写的代码的示例,以使我的表面保持不变。

 Z=[]
    Z.append([20.2, 20.1, 35])
    Z.append([20.1, 24.5, 36])

 Z.append([21.0, 23.2, 33])
    Z.append([22.3, 20.0, 34])
    Z.append([22.3, 19.5, 28])
    Z.append([20.1, 19.5, 27])
    Z.append([20.1, 24.6, 31])
    Z.append([22.3, 24.6, 32])
    # ---------------------------
    xin=np.array(Z)[:,0];
    yin=np.array(Z)[:,1];
    zin=np.array(Z)[:,2];
    # ----------------------------
    xout=np.linspace(20.,23.,10);
    yout=np.linspace(19.,25.,10);
    xout,yout = np.meshgrid(xout,yout);
    # ----------------------------
    zout=griddata((xin,yin),zin,(xout,yout),'cubic');
    # -----------------------------
    from pylab import pcolormesh,show
    pcolormesh(xout,yout,zout);show();

Lets say I have a point (21.0, 20.0, 60) and it is rotated 9 degrees to north, 2 degrees to east (here 21.0 represents longitude, 20.0 - latitude, 60 - altitude). 假设我有一个点(21.0,20.0,60),它向北旋转9度,向东旋转2度(此处21.0代表经度,20.0-纬度,60-海拔)。

Not an easy problem. 这不是一个简单的问题。

As it seems, your interpolant is piecewise, presumably defined over a triangulation (if not, please specify). 看来,您的插值器是分段的,大概是在三角剖分中定义的(如果没有,请指定)。

If you know the expression of the interpolant, presumably a cubic polynomial, you can determine the range of values taken on every tile (you need to find the stationary points inside, those on the edges and the values at the corners). 如果知道插值的表达式(大概是三次多项式),则可以确定每个图块所取值的范围(您需要找到内部的固定点,边缘的固定点和角的值)。

This creates a bounding volume for every patch, and the surface is wrapped in vertical, non-overlapping prisms. 这将为每个贴片创建一个边界体积,并且该表面将包裹在垂直的,不重叠的棱镜中。

Now for a given ray, you project it on the XY plane, and see which prism base it crosses. 现在,对于给定的光线,将其投影在XY平面上,然后查看它与哪个棱镜底面交叉。 If the bases are convex polygons, it will cross them along a line segment. 如果底面是凸多边形,它将沿线段与底面相交。 For the entry and exit points, compute the Z value (along the ray) and check if there is an overlap with the Z range of the patch. 对于入口点和出口点,计算Z值(沿射线),并检查是否与面片的Z范围重叠。

Finally, when you have found a hit, solve the system formed by the parametric equation of the ray and the explicit equation of the surface. 最后,找到命中点后,求解由射线的参数方程和曲面的显式方程组成的系统。 In the case of a cubic surface, this gives a cubic polynomial, for which analytical formulas are available. 在三次曲面的情况下,给出三次多项式,可以使用该多项式的分析公式。 There can be up to three solutions. 最多可以有三个解决方案。

You should trace the ray starting from the source and stop as soon as you have found a solution (if there are several intersections in the same patch, keep the closes to the source). 您应该从源头开始追踪光线,并在找到解决方案后立即停止(如果同一面片中有多个交叉点,则保持靠近源头)。

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

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