Normal Transformation(法线变换)

本文探讨了在3D图形中,为何不能直接使用模型变换矩阵进行法线变换,原因是非一致性的缩放会导致法线方向错误。通过数学推导,解释了使用逆转置矩阵来变换法线以保持其与切线垂直的关系。还提到了在不可逆矩阵或仅考虑旋转时的处理方式,并指出在三向一致缩放的情况下,可以直接用变换矩阵进行法线变换。对于建模工具开发,处理任意缩放变换是关键问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于三维空间法线变换的问题,之前就有看到过,但是一直也木有注意,普通的三维空间中的法线变换还是直接使用模型的变换矩阵来进行。但是,近来又看到了一些这方面相关的东西,因而总结一下。

已经知道不能直接用模型变换矩阵来变换Normal,比如使用某含有非一致性缩放(在x,y,z方向上进行不程度的拉伸)的变换矩阵来变换一球体,则可能得到如下列图示的结果:

  

左图为原始球体及其表面上的法向分布(2D投影后);中间为直接使用变换矩阵操作后的法向分布,但注意其明显与表面不垂直;右图为正确变换后的法向分布。
为什么直接变换不正确呢?网上有多种说明版本,但是对比了一下感觉还是PBRT上的解释比较好一些。这里假设某一点处的法向量为n&#

//粗配准 void PointProcessing::coarseRegistration( const std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr>& clusters, // 多簇源点云 const pcl::PointCloud<pcl::PointXYZ>::Ptr& target, // 目标点云 std::vector<Eigen::Matrix4f>& transformation_matrices, // 输出变换矩阵集合 float sac_ia_max_distance, // SAC-IA最大对应距离 int feature_radius // FPFH特征半径 ) { transformation_matrices.clear(); // 遍历每个簇 for (const auto& cluster : clusters) { // --- 1. 源簇关键点提取 --- pcl::PointCloud<pcl::PointXYZ>::Ptr src_keypoints(new pcl::PointCloud<pcl::PointXYZ>); pcl::UniformSampling<pcl::PointXYZ> uniform_sampling; uniform_sampling.setInputCloud(cluster); uniform_sampling.setRadiusSearch(2.0); // 关键点采样半径(可参数化) uniform_sampling.filter(*src_keypoints); // --- 2. 目标关键点提取(复用同一采样器)--- pcl::PointCloud<pcl::PointXYZ>::Ptr tgt_keypoints(new pcl::PointCloud<pcl::PointXYZ>); uniform_sampling.setInputCloud(target); uniform_sampling.filter(*tgt_keypoints); // --- 3. 使用自定义函数计算法线 --- pcl::PointCloud<pcl::Normal>::Ptr src_normals(new pcl::PointCloud<pcl::Normal>); computernormals(src_keypoints, src_normals, 5.0); // 法线半径5.0 pcl::PointCloud<pcl::Normal>::Ptr tgt_normals(new pcl::PointCloud<pcl::Normal>); computernormals(tgt_keypoints, tgt_normals, 5.0); // --- 4. 使用自定义函数计算FPFH特征 --- pcl::PointCloud<pcl::FPFHSignature33>::Ptr src_features(new pcl::FPFHSignature33); computerFPFH(src_keypoints, src_normals, src_features, feature_radius); pcl::PointCloud<pcl::FPFHSignature33>::Ptr tgt_features(new pcl::FPFHSignature33); computerFPFH(tgt_keypoints, tgt_normals, tgt_features, feature_radius); // --- 5. SAC-IA配准 --- pcl::SampleConsensusInitialAlignment<pcl::PointXYZ, pcl::PointXYZ, pcl::FPFHSignature33> sac_ia; sac_ia.setInputSource(src_keypoints); sac_ia.setSourceFeatures(src_features); sac_ia.setInputTarget(tgt_keypoints); sac_ia.setTargetFeatures(tgt_features); sac_ia.setMaxCorrespondenceDistance(sac_ia_max_distance); pcl::PointCloud<pcl::PointXYZ>::Ptr aligned(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr aligned(new pcl::PointCloud<pcl::PointXYZ>); sac_ia.align(*aligned); // 无返回值,直接执行 // 检查变换矩阵有效性 Eigen::Matrix4f matrix = sac_ia.getFinalTransformation(); if (!matrix.isZero() && !matrix.hasNaN()) { transformation_matrices.push_back(matrix); } else { transformation_matrices.push_back(Eigen::Matrix4f::Identity()); } } }其中clusters是一个包含多个聚类的容器,修改这个函数,循环遍历clusters,计算法线与特征,随后与target进行粗配准
最新发布
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值