游戏数学之linear algebra(一)

本文介绍了游戏开发中线性代数的基础概念,包括右手系和左手系的区别、矢量运算(点积和叉积)、矩阵变换(平移、旋转、缩放)。讨论了如何利用这些数学工具解决游戏中的方向判断、自由视角实现等问题,并探讨了坐标系变换的重要性和方法。
摘要由CSDN通过智能技术生成

游戏数学之linear algebra(一)

本文转自我的公众号—游戏开发手账
转载请标明出处

当你发现自己一进游戏世界就找不到北的时候,你心里就该清楚这点了,欠下线代大爹的债死也不还总是要还的。

右手系和左手系

这个找不到北的问题的起点,可能要从坐标系说起,左手系和右手系的区别在于它们笛卡尔坐标轴中有一个轴的方向是不同的(在游戏中通常为z轴),一个判断左手系和右手系的方法,拇指食指中指三者两两呈90°摆好,看看哪个手对的上。

一般的设定是,中指为x轴向右,拇指为y轴向上,这样你会发现左手系中食指的指向(z轴正向)是向远离你的方向,右手系中是接近你的方向。

好的,这样单纯在自己的视角上,算是找得到北了。

矢量运算
  • 矢量和标量的乘法

    • 可以把相乘的标量当作缩放因子,矢量 n ⃗ \vec n n ,标量 a a a a n = ( a x n ⃗ x , a y n ⃗ y , a z n ⃗ z ) an = (a_{x}\vec n_{x} ,a_{y}\vec n_{y}, a_{z}\vec n_{z}) an=(axn x,ayn y,azn z),如果 a a a中的每个分量值不同,这种缩放称为非统一缩放。
  • 矢量的加减法

    • 矢量的加减法将矢量中每个分量分别相加/减即可。
  • 矢量的模

    • 用于求长度。

    • 矢量运算可以用于人物移动,根据本帧位置和速度求人物下一帧位置;还可用于物体的碰撞/相交检测(矢量减法再求模)。

矢量的点积和叉积
  • 点积有什么用处
    • 当点积中一个矢量是单位向量时,所得值为另一矢量在该单位向量方向上的投影长度📏。

    • 在这里插入图片描述

    • 利用点积,可以判定两矢量的方向大致在什么样的相对方向上。所得值大于零的话,二者夹角小于90°,反之大于90°(分别对应下图的红色部分和蓝色部分),等于零时二者方向垂直。更多的,还可以判断是否共线或反向共线。

    • 在这里插入图片描述

    • 应用的话,你可以考虑这样的功能:当你要实现TPS游戏中的“自由视角”功能时(自由视角是指切换成此类视角时,人物呈原地站立状,鼠标的移动不再和人物的视角方向绑定,通过鼠标的移动,你可以环绕地观察自身角色,当镜头朝向人物时,人物的视线会注视向镜头的方向),为了写镜头在人身后和在前面面向人物的不同逻辑,可以用点积判断二者的相对角度并分写逻辑。

    • 具体来说,人物位置 p ⃗ \vec p p ,相机位置 c ⃗ \vec c c ,人物朝向 f ⃗ \vec f f c ⃗ − p ⃗ \vec c - \vec p c p 得到人物至相机的矢量,再点积人物朝向。 f ⃗ \vec f f

  • 关于叉积
    • 叉积的方向垂直于相乘的两个矢量构成的平面,模为 ∣ a ⃗ ∣ ∣ b ⃗ ∣ sin ⁡ θ |\vec a||\vec b|\sin θ a b sinθ,叉积模的值等于两矢量构成的平行四边形的面积,叉积可以用于求平面的法矢量。
    • 要注意的是叉积的方向会根据坐标系的选择而改变,当使用右手坐标系时,叉积方向的判断使用右手法则,左手坐标系时使用左手法则。
    • 以右手法则举例,四指指向
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
About the Author David C. Lay holds a B.A. from Aurora University (Illinois), and an M.A. and Ph.D. from the University of California at Los Angeles. David Lay has been an educator and research mathematician since 1966, mostly at the University of Maryland, College Park. He has also served as a visiting professor at the University of Amsterdam, the Free University in Amsterdam, and the University of Kaiserslautern, Germany. He has published more than 30 research articles on functional analysis and linear algebra. As a founding member of the NSF-sponsored Linear Algebra Curriculum Study Group, David Lay has been a leader in the current movement to modernize the linear algebra curriculum. Lay is also a coauthor of several mathematics texts, including Introduction to Functional Analysis with Angus E. Taylor, Calculus and Its Applications, with L. J. Goldstein and D. I. Schneider, and Linear Algebra Gems–Assets for Undergraduate Mathematics, with D. Carlson, C. R. Johnson, and A. D. Porter. David Lay has received four university awards for teaching excellence, including, in 1996, the title of Distinguished Scholar—Teacher of the University of Maryland. In 1994, he was given one of the Mathematical Association of America’s Awards for Distinguished College or University Teaching of Mathematics. He has been elected by the university students to membership in Alpha Lambda Delta National Scholastic Honor Society and Golden Key National Honor Society. In 1989, Aurora University conferred on him the Outstanding Alumnus award. David Lay is a member of the American Mathematical Society, the Canadian Mathematical Society, the International Linear Algebra Society, the Mathematical Association of America, Sigma Xi, and the Society for Industrial and Applied Mathematics. Since 1992, he has served several terms on the national board of the Association of Christians in the Mathematical Sciences. Steven R. Lay began his teaching career at Aurora University (Illinois) in 1971, after earning an M.A. and a Ph.D. in mathematics from the University of California at Los Angeles. His career in mathematics was interrupted for eight years while serving as a missionary in Japan. Upon his return to the States in 1998, he joined the mathematics faculty at Lee University (Tennessee) and has been there ever since. Since then he has supported his brother David in refining and expanding the scope of this popular linear algebra text, including writing most of Chapters 8 and 9. Steven is also the author of three college-level mathematics texts: Convex Sets and Their Applications, Analysis with an Introduction to Proof, and Principles of Algebra. In 1985, Steven received the Excellence in Teaching Award at Aurora University. He and David, and their father, Dr. L. Clark Lay, are all distinguished mathematicians, and in 1989 they jointly received the Outstanding Alumnus award from their alma mater, Aurora University. In 2006, Steven was honored to receive the Excellence in Scholarship Award at Lee University. He is a member of the American Mathematical Society, the Mathematics Association of America, and the Association of Christians in the Mathematical Sciences. Judi J. McDonald joins the authorship team after working closely with David on the fourth edition. She holds a B.Sc. in Mathematics from the University of Alberta, and an M.A. and Ph.D. from the University of Wisconsin. She is currently a professor at Washington State University. She has been an educator and research mathematician since the early 90s. She has more than 35 publications in linear algebra research journals. Several undergraduate and graduate students have written projects or theses on linear algebra under Judi’s supervision. She has also worked with the mathematics outreach project Math Central http://mathcentral.uregina.ca/ and continues to be passionate about mathematics education and outreach. Judi has received three teaching awards: two Inspiring Teaching awards at the University of Regina, and the Thomas Lutz College of Arts and Sciences Teaching Award at Washington State University. She has been an active member of the International Linear Algebra Society and the Association for Women in Mathematics throughout her career and has also been a member of the Canadian Mathematical Society, the American Mathematical Society, the Mathematical Association of America, and the Society for Industrial and Applied Mathematics.
Contents Preface to the Third Edition, vii Preface to the Second Edition, ix Preface to the First Edition, xi Preliminaries, 1 Part 1: Preliminaries, 1 Part 2: Algebraic Structures, 17 Part I---Basic Linear Algebra, 33 1 Vector Spaces, 35 Vector Spaces, 35 Subspaces, 37 Direct Sums, 40 Spanning Sets and Linear Independence, 44 The Dimension of a Vector Space, 48 Ordered Bases and Coordinate Matrices, 51 The Row and Column Spaces of a Matrix, 52 The Complexification of a Real Vector Space, 53 Exercises, 55 2 Linear Transformations, 59 Linear Transformations, 59 The Kernel and Image of a Linear Transformation, 61 Isomorphisms, 62 The Rank Plus Nullity Theorem, 63 Linear Transformations from to , 64 Change of Basis Matrices, 65 The Matrix of a Linear Transformation, 66 Change of Bases for Linear Transformations, 68 Equivalence of Matrices, 68 Similarity of Matrices, 70 Similarity of Operators, 71 Invariant Subspaces and Reducing Pairs, 72 Projection Operators, 73 xiv Contents Topological Vector Spaces, 79 Linear Operators on , 82 Exercises, 83 3 The Isomorphism Theorems, 87 Quotient Spaces, 87 The Universal Property of Quotients and the First Isomorphism Theorem, 90 Quotient Spaces, Complements and Codimension, 92 Additional Isomorphism Theorems, 93 Linear Functionals, 94 Dual Bases, 96 Reflexivity, 100 Annihilators, 101 Operator Adjoints, 104 Exercises, 106 4 Modules I: Basic Properties, 109 Motivation, 109 Modules, 109 Submodules, 111 Spanning Sets, 112 Linear Independence, 114 Torsion Elements, 115 Annihilators, 115 Free Modules, 116 Homomorphisms, 117 Quotient Modules, 117 The Correspondence and Isomorphism Theorems, 118 Direct Sums and Direct Summands, 119 Modules Are Not as Nice as Vector Spaces, 124 Exercises, 125 5 Modules II: Free and Noetherian Modules, 127 The Rank of a Free Module, 127 Free Modules and Epimorphisms, 132 Noetherian Modules, 132 The Hilbert Basis Theorem, 136 Exercises, 137
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

闲倾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值