cgal-空间直线的的最小距离

question:

have two lines/rays in 3d and want to get the shortest line that connects both (or similarly: the 3d point that has the shortest  distance to both lines)


code :

// get plane p1 that contains l1 and is parallel to l2
Plane_3 p1( l1, l1.point(0) + l2.to_vector() );

// get plane p2 that contains l1 and is perpendicular to p1

Plane_3 p2( l1, l1.point(0) + p1.orthogonal_vector() );

// get intersection i1 between p2 and l2

Point_3 i1;
CGAL::Object result = CGAL::intersection( p2, l2 );
if( !assign( i1, result ) ) {
       Line_3 il;
       if( assign( il, result ) )
               std::cout << "intersection between plane and line is a line --> l1 and l2 are parallel!" << std::endl;
       return -1.0;
}

// get intersection i2 on l1

Point_3 i2 = l1.projection( i1 );

// final point is (i1+i2)/2

Point_3 f((i1.x() + i2.x()) / 2.0, (i1.y() + i2.y()) / 2.0, (i1.z() + i2.z()) / 2.0);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值