如何计算三维空间圆柱体间的最小距离?
如何计算三维空间圆柱体间的最小距离? 把圆柱看成直线,求两条直线的最短距离,再减去两个圆柱的半径不就可以了。 分别列出曲面方程,求两曲面上最近的点对。 每个圆柱由三个面和两条边界(圆)共五个对象构成,两个圆柱可以求出5*5种最短距离,首先判断每个最短距离使用的点是否在合法范围,然后此后在所有合法的最短距离中找出最终的最短距离即可 示例。% = dcylinders(A0, r0, A1, r1)
% Distance between 2 cylinders in 3D
% INPUTS:
% A0: 3x2 array, each column is the end of axis of cylinder 0
% r0: scalar, radius of cylinder 0
% A1: 3x2 array, each column is the end of axis of cylinder 1
% r1: scalar, radius of cylinder 1
% OUTPUTS:
% Distance: scalar, if positive, the distance between 2 cylinders
% meaning Distance = min{ |x-y| : x in cylinder0, y in cylinder1 }
% where |.| is euclidian distance
% If Distance < 0 the cylinders intersect
% P0, P1 closest points, P0 in cylinder0, P1 in cylinder1 such that
% Distance = |P0-P1|.
% Required: MATLAB 2018a 10个测试案例:
case -1
A0 = [-2 -1 0;
4 3 0].';
r0 = 2.2;
A1 = [10 -1 1;
16 3 1].';
r1 = 0.3;
case 0
A0 = [-2 -1 0;
4 3 0].';
r0 = 0.2;
A1 = [-2 -1 1;
4 3 1].';
r1 = 0.3;
case 1
A0 = [-2 -1 0;
4 3 0].';
r0 = 0.2;
A1 = [-1 2 1;
5 -1 2].';
r1 = 0.3;
case 2
A0 = [-2 -1 0;
4 3 0].';
r0 = 0.5;
A1 = [3 0 1;
5 -1 0].';
r1 = 0.3;
case 3
A0 = [-2 -1 0;
1 1 0].';
r0 = 2;
A1 = [3 2 1;
5 1 1].';
r1 = 1;
case 4
A0 = [-2 -1 0;
1 1 0].';
r0 = 1;
A1 = [3 0 1;
5 -1 0].';
r1 = 0.5;
case 5
A0 = [-2 0 0;
5 0 0].';
r0 = 1;
A1 = [1 3 1;
1 7 1].';
r1 = 1.2;
case 6
A0 = [-2 0 0;
5 0 0].';
r0 = 0.5;
A1 = [1 2 0;
4 1 0].';
r1 = 0.5;
case 7
A0 = [-3 0 0;
0 0 0].';
r0 = 3;
A1 = [0.5 0 -0.5;
3.5 3 0].';
r1 = 2;
case 8
A0 = [-3 0 0;
0 0 0].';
r0 = 0.2;
A1 = [0.5 0 0.2;
-3 -3 0].';
r1 = 0.2;
>> test_dcylinders
Compile conv1使用 'Microsoft Visual C++ 2013 (C)' 编译。
MEX 已成功完成。
Distance =
0.0091
Distance =
-1.8432
Distance =
0.0257
Distance =
2
Distance =
1.2818
Distance =
1.3506
Distance =
1.4315
Distance =
0.8141
Distance =
0.5000
Distance =
5.0591
>> 部分计算图像示例
本帖最后由 灵树 于 2020-5-4 11:20 编辑
可以化简为求两线轴心线和端面上与另一个轴心线垂直的半径,这样几条线段空间距离的问题, 正方体内随机投放圆柱体,达到预定的体积比例;判断两圆柱体间的距离,距离为负即为相交,为正,不相交。
页:
[1]