2.13 转换矩阵
转换矩阵引用了库nalgebra,使用时研究具体实现。
use std::ops;use nalgebra::Perspective3;use crate::Scalar;use super::{Aabb, LineSegment, Point, Triangle, Vector};/// An affine transform
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct Transform(nalgebra::Transform<f64, nalgebra::TAffine, 3>);impl Transform {/// Construct an identity transformpub fn identity() -> Self {Self(nalgebra::Transform::identity())}/// Construct a translationpub fn translation(offset: impl Into<Vector<3>>) -> Self {let offset = offset.into();Self(nalgebra::Transform::from_matrix_unchecked(nalgebra::OMatrix::new_translation(&offset.to_na()),))}/// Construct a rotation////// The direction of the vector defines the rotation axis. Its length/// defines the angle of the rotation.pub fn rotation(axis_angle: impl Into<Vector<3>>) -> Self {let axis_angle = axis_angle.into();Self(nalgebra::Transform::from_matrix_unchecked(nalgebra::OMatrix::<_, nalgebra::Const<4>, _>::new_rotation(axis_angle.to_na(),),))}/// Construct a scalingpub fn scale(scaling_factor: f64) -> Self {Self(nalgebra::Transform::from_matrix_unchecked(nalgebra::OMatrix::new_scaling(scaling_factor),))}/// # Extract the "right" vector from the rotational componentpub fn right(&self) -> Vector<3> {let d = self.data();Vector::from([d[0], d[1], d[2]])}/// # Extract the "up" vector from the rotational componentpub fn up(&self) -> Vector<3> {let d = self.data();Vector::from([d[4], d[5], d[6]])}/// Transform the given pointpub fn transform_point(&self, point: &Point<3>) -> Point<3> {Point::from(self.0.transform_point(&point.to_na()))}/// Inverse transform given pointpub fn inverse_transform_point(&self, point: &Point<3>) -> Point<3> {Point::from(self.0.inverse_transform_point(&point.to_na()))}/// Transform the given vectorpub fn transform_vector(&self, vector: &Vector<3>) -> Vector<3> {Vector::from(self.0.transform_vector(&vector.to_na()))}/// Transform the given segmentpub fn transform_segment(&self,segment: &LineSegment<3>,) -> LineSegment<3> {let [a, b] = &segment.points;LineSegment::from([self.transform_point(a), self.transform_point(b)])}/// Transform the given trianglepub fn transform_triangle(&self, triangle: &Triangle<3>) -> Triangle<3> {let [a, b, c] = &triangle.points;Triangle::from([self.transform_point(a),self.transform_point(b),self.transform_point(c),])}/// Inverse transformpub fn inverse(&self) -> Self {Self(self.0.inverse())}/// Transpose transformpub fn transpose(&self) -> Self {Self(nalgebra::Transform::from_matrix_unchecked(self.0.to_homogeneous().transpose(),))}/// Project transform according to camera specification, return data as an array./// Used primarily for graphics code.pub fn project_to_array(&self,aspect_ratio: f64,fovy: f64,znear: f64,zfar: f64,) -> [Scalar; 16] {let projection = Perspective3::new(aspect_ratio, fovy, znear, zfar);let mut array = [0.; 16];array.copy_from_slice((projection.to_projective() * self.0).matrix().as_slice(),);array.map(Scalar::from)}/// Return a copy of the inner nalgebra transformpub fn get_inner(&self) -> nalgebra::Transform<f64, nalgebra::TAffine, 3> {self.0}/// Transform the given axis-aligned bounding boxpub fn transform_aabb(&self, aabb: &Aabb<3>) -> Aabb<3> {Aabb {min: self.transform_point(&aabb.min),max: self.transform_point(&aabb.max),}}/// Exposes the data of this Transform as a slice of f64.pub fn data(&self) -> &[f64] {self.0.matrix().data.as_slice()}/// Extract the rotation component of this transformpub fn extract_rotation(&self) -> Self {Self(nalgebra::Transform::from_matrix_unchecked(self.0.matrix().fixed_resize::<3, 3>(0.).to_homogeneous(),))}/// Extract the translation component of this transformpub fn extract_translation(&self) -> Self {*self * self.extract_rotation().inverse()}
}impl ops::Mul<Self> for Transform {type Output = Self;fn mul(self, rhs: Self) -> Self::Output {Self(self.0.mul(rhs.0))}
}#[cfg(test)]
mod tests {use approx::assert_abs_diff_eq;use crate::{Scalar, Vector};use super::Transform;#[test]fn extract_rotation_translation() {let rotation =Transform::rotation(Vector::unit_z() * (Scalar::PI / 2.));let translation = Transform::translation([1., 2., 3.]);assert_abs_diff_eq!((translation * rotation).extract_rotation().data(),rotation.data(),epsilon = 1e-8,);assert_abs_diff_eq!((translation * rotation).extract_translation().data(),translation.data(),epsilon = 1e-8,);assert_abs_diff_eq!((rotation * translation).extract_rotation().data(),rotation.data(),epsilon = 1e-8,);assert_abs_diff_eq!((rotation * translation).extract_translation().data(),Transform::translation([-2., 1., 3.]).data(),epsilon = 1e-8,);}
}相关文章:
2.13 转换矩阵
转换矩阵引用了库nalgebra,使用时研究具体实现。 use std::ops;use nalgebra::Perspective3;use crate::Scalar;use super::{Aabb, LineSegment, Point, Triangle, Vector};/// An affine transform #[repr(C)] #[derive(Debug, Clone, Copy, Default)] pub struct…...
【C语言】遗传算法matlab程序
遗传算法matlab程序 遗传算法是一种模拟自然选择过程的优化技术,用于解决复杂问题。在MATLAB中编写遗传算法程序,通常包括以下几个步骤: 初始化种群:创建一个初始解集(种群),每个解代表一个问题…...
Java LinkedList 详解
LinkedList 是 Java 集合框架中常用的数据结构之一,位于 java.util 包中。它实现了 List、Deque 和 Queue 接口,是一个双向链表结构,适合频繁的插入和删除操作。 1. LinkedList 的特点 数据结构:基于双向链表实现,每个…...
mac-mini的时间机器,数据备份到alist 中的网盘
苹果的时间机器不能直接将备份存储在 alist 上的网盘,但可以通过一些中间步骤来实现类似的效果,以下是具体介绍: 方法原理 通过将支持 WebDAV 协议的网络存储挂载到本地,再将其设置为时间机器的备份磁盘,从而间接实现…...
【HarmonyOS】鸿蒙应用加载读取csv文件
【HarmonyOS】鸿蒙应用加载读取csv文件 一、问题背景: 1. csv文件是什么? csv是一种文本文件格式,与json类似。会存储一些文本内容,应用需要读取该文件,进行UI内容得填充等。 文件中的数据是以纯文本形式存储的&…...
Java retainAll() 详解
在 Java 中,retainAll() 是 Collection 接口(List、Set 等集合类实现该接口)的一种方法,用于保留集合中与指定集合交集的元素,删除其他所有元素。 以下是对 retainAll() 方法的详细讲解。 1. 方法定义 方法签名 boo…...
Redis的基本数据类型
初识Redis缓存 Redis缓存: 实际开发中经常使用Redis作为缓存数据库,从而提高数据存取效率,减轻后端数据库的压力。 可以将经常被查询的数据缓存起来,比如热点数据,这样当用户来访问的时候,就不需要到MyS…...
通过vite+vue3+pinia从0到1搭建一个uniapp应用
最近项目上要做一个app,选择了用uniapp作为开发框架;我大概看了一下uniapp的文档,根据文档从0到1搭了一个uniapp应用供大家参考。 因为本人习惯使用了WebStorm编译器,但是uniapp官方推荐使用HBuilder搭建,如果和我一样…...
Linux的桌面
Linux的桌面是可以卸载的 的确,Linux并不像Windows,Linux本身是一个基于命令行的操作系统,在内核眼中,桌面只不过是个普通的应用程序,所以,在Linux的桌面中可以完成的事情,命令行中也基本可以完…...
Easyexcel(5-自定义列宽)
相关文章链接 Easyexcel(1-注解使用)Easyexcel(2-文件读取)Easyexcel(3-文件导出)Easyexcel(4-模板文件)Easyexcel(5-自定义列宽) 注解 ColumnWidth Data…...
操作系统实验 C++实现死锁检测算法
实验目的 模拟实现死锁检测算法 实验内容 1、 输入: “资源分配表”文件,每一行包含资源编号、进程编号两项(均用整数表示,并用空格分隔开),记录资源分配给了哪个进程。 “进程等待表”文件&…...
小鹏汽车智慧材料数据库系统项目总成数据同步
1、定时任务处理 2、提供了接口 小鹏方面提供的推送的数据表结构: 这几个表总数为100多万,经过条件筛选过滤后大概2万多条数据 小鹏的人给的示例图: 界面: SQL: -- 查询车型 select bmm.md_material_id, bmm.material_num, bm…...
1、HCIP之RSTP协议与STP相关安全配置
目录 RSTP—快速生成树协议 STP STP的缺点: STP的选举(Listening状态中): RSTP P/A(提议/同意)机制 同步机制: 边缘端口的配置: RSTP的端口角色划分: ensp模拟…...
Linux云服务器docker使用教程
诸神缄默不语-个人CSDN博文目录 我用的是腾讯云服务器,操作系统是OpenCloudOS 9,基本上可以当特色版CentOS用。 docker安装跟各个系统关系太大了,我就不写了。OpenCloudOS 9安装docker见这篇博文:腾讯云服务器使用教程 文章目录 …...
如何从android的webview 取得页面上的数据
要从Android的WebView中获取页面上的数据,通常有几种常见的方法: JavaScript Interface:通过JavaScript和Android Interface进行通信。这种方法允许你在JavaScript中调用Android的方法,反之亦然。 Evaluate JavaScriptÿ…...
VTK知识学习(12)- 读取PNG图像
1、代码 private void ShowPngImage(){vtkPNGReader pngReader vtkPNGReader.New();pngReader.SetFileName("D:\\图像\\boxes\\cardboard_boxes_01.png");pngReader.Update();vtkImageActor imageActor vtkImageActor.New();imageActor.SetInputData(pngReader.Get…...
Springboot项目搭建(3)-更改用户信息与文件上传
1.概要 前一章节完成了用户信息的注册、登录、详细信息查询,以及线程池与拦截器技术。 这一章完善了用户信息更新/更改功能,包括昵称、邮箱、头像、密码等... 而后接触到了本地上传和云上传,其二者区别: 选择本地上传还是云上…...
Docker1:认识docker、在Linux中安装docker
欢迎来到“雪碧聊技术”CSDN博客! 在这里,您将踏入一个专注于Java开发技术的知识殿堂。无论您是Java编程的初学者,还是具有一定经验的开发者,相信我的博客都能为您提供宝贵的学习资源和实用技巧。作为您的技术向导,我将…...
python成绩分级 2024年6月python二级真题 青少年编程电子学会编程等级考试python二级真题解析
目录 python成绩分级 一、题目要求 1、编程实现 2、输入输出 二、算法分析 三、程序代码 四、程序说明 五、运行结果 六、考点分析 七、 推荐资料 1、蓝桥杯比赛 2、考级资料 3、其它资料 python成绩分级 2024年6月 python编程等级考试二级编程题 一、题目要求 …...
android 如何获取当前 Activity 的类名和包名
其一:getClass().getSimpleName() public static String getTopActivity(Context context){ ActivityManager am (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE); ComponentName cn am.getRunningTasks(1).get(0).topAct…...
JavaScript 中的 ES|QL:利用 Apache Arrow 工具
作者:来自 Elastic Jeffrey Rengifo 学习如何将 ES|QL 与 JavaScript 的 Apache Arrow 客户端工具一起使用。 想获得 Elastic 认证吗?了解下一期 Elasticsearch Engineer 培训的时间吧! Elasticsearch 拥有众多新功能,助你为自己…...
el-switch文字内置
el-switch文字内置 效果 vue <div style"color:#ffffff;font-size:14px;float:left;margin-bottom:5px;margin-right:5px;">自动加载</div> <el-switch v-model"value" active-color"#3E99FB" inactive-color"#DCDFE6"…...
大学生职业发展与就业创业指导教学评价
这里是引用 作为软工2203/2204班的学生,我们非常感谢您在《大学生职业发展与就业创业指导》课程中的悉心教导。这门课程对我们即将面临实习和就业的工科学生来说至关重要,而您认真负责的教学态度,让课程的每一部分都充满了实用价值。 尤其让我…...
.Net Framework 4/C# 关键字(非常用,持续更新...)
一、is 关键字 is 关键字用于检查对象是否于给定类型兼容,如果兼容将返回 true,如果不兼容则返回 false,在进行类型转换前,可以先使用 is 关键字判断对象是否与指定类型兼容,如果兼容才进行转换,这样的转换是安全的。 例如有:首先创建一个字符串对象,然后将字符串对象隐…...
微软PowerBI考试 PL300-在 Power BI 中清理、转换和加载数据
微软PowerBI考试 PL300-在 Power BI 中清理、转换和加载数据 Power Query 具有大量专门帮助您清理和准备数据以供分析的功能。 您将了解如何简化复杂模型、更改数据类型、重命名对象和透视数据。 您还将了解如何分析列,以便知晓哪些列包含有价值的数据,…...
MySQL 8.0 事务全面讲解
以下是一个结合两次回答的 MySQL 8.0 事务全面讲解,涵盖了事务的核心概念、操作示例、失败回滚、隔离级别、事务性 DDL 和 XA 事务等内容,并修正了查看隔离级别的命令。 MySQL 8.0 事务全面讲解 一、事务的核心概念(ACID) 事务是…...
从“安全密码”到测试体系:Gitee Test 赋能关键领域软件质量保障
关键领域软件测试的"安全密码":Gitee Test如何破解行业痛点 在数字化浪潮席卷全球的今天,软件系统已成为国家关键领域的"神经中枢"。从国防军工到能源电力,从金融交易到交通管控,这些关乎国计民生的关键领域…...
wpf在image控件上快速显示内存图像
wpf在image控件上快速显示内存图像https://www.cnblogs.com/haodafeng/p/10431387.html 如果你在寻找能够快速在image控件刷新大图像(比如分辨率3000*3000的图像)的办法,尤其是想把内存中的裸数据(只有图像的数据,不包…...
提升移动端网页调试效率:WebDebugX 与常见工具组合实践
在日常移动端开发中,网页调试始终是一个高频但又极具挑战的环节。尤其在面对 iOS 与 Android 的混合技术栈、各种设备差异化行为时,开发者迫切需要一套高效、可靠且跨平台的调试方案。过去,我们或多或少使用过 Chrome DevTools、Remote Debug…...
第一篇:Liunx环境下搭建PaddlePaddle 3.0基础环境(Liunx Centos8.5安装Python3.10+pip3.10)
第一篇:Liunx环境下搭建PaddlePaddle 3.0基础环境(Liunx Centos8.5安装Python3.10pip3.10) 一:前言二:安装编译依赖二:安装Python3.10三:安装PIP3.10四:安装Paddlepaddle基础框架4.1…...
