Pixel World

it's better be burning out than to fade away.

图形学的数学基础(二):标准正交基/坐标系

标准正交基

对于三维空间任意三个向量,如果它们满足

  • $||\vec{u}|| = ||\vec{v}|| = ||\vec{w}|| = 1$
  • $\vec{u}.\vec{v} = \vec{v}.\vec{w} = \vec{u}.\vec{w} = 0$
  • $\vec{w} = \vec{u} \times \vec{v}$ (右手系)

即向量长度都为1,相互垂直, 这样的三个向量构成的坐标系称为标准正交基,$\vec{u} ,\vec{v},\vec{w}$称为标准正交基的基矢量.

为什么需要标准正交基

定义这样的坐标系,带来的一点好处就是, 空间中任意一矢量,都可以分解到标准正交基的三个轴上,需要用到前边向量投影的相关知识. 即矢量可以表示为基矢量的线性组合.
alt

$||\vec{b_⊥}|| = ||\vec{b}|| \cos\theta$

此时的$\vec{a}$为单位向量,即$||\vec{a}|| = 1$

阅读全文 »

图形学的数学基础(一):向量

前边的话

本系列是阅读《3D数学基础: 图形和游戏开发(第二版)》整理汇总的学习笔记,整个系列的结构排布基于原书的章节安排,针对其中的每个知识点做了适当的补充和拓展,其中不免有遗漏和错误之处,望各位读者批评指正。本篇文章做为该系列的第一章,主要介绍向量相关内容,涉及空间中向量的几何意义,各种运算,重点介绍点乘和叉乘的几何解释及在图形学中的应用场景。

数学定义

对于数学家来说向量是一个数组,数组的长度代表向量所在的空间维度。程序中表示向量通常有两种方式,行向量($Row Vector$)和列向量($Column Vector$),至于为什么要区分两种书写方式,我们放到矩阵章节再详细说明.

$V_{column} = \begin{bmatrix}1\\ 2\\ 3\end{bmatrix}$

$V_{row} = \begin{bmatrix}1&2&-1\end{bmatrix}$

几何定义

从几何学上讲,向量是具有大小和方向的有向线段.讨论向量在空间中的哪个位置,是没有意义的,向量不具备位置属性.向量是一种相对偏移量的表示方法.如下图二维笛卡尔坐标系中,向量U和V是相等的.

阅读全文 »

基础知识

指数法则

  1. $b^0=1$

  2. $b^1=b$

  3. $b^xb^y=b^{x+y}$

  4. $\frac{b^x}{b^y}=b^{x-y}$

  5. $(b^x)^y=b^{xy}$

对数法则

  1. $b^{\log_by}=y$

  2. $\log_b1=0$

  3. $\log_bb=1$

  4. $\log_b{(xy)}=\log_bx+\log_by$

  5. $\log_b(\frac{x}{y})=\log_bx-\log_by$

  6. $\log_b(x^y)=y\log_bx$

  7. $\log_bx=\frac{\log_cx}{\log_cb}$

  8. $\log_xy=\frac{1}{\log_yx}$

e

关于e的四个定义:

$\lim_{h \to \infty}(1+\frac{r}{h})^h=e^r$

$\lim_{h \to 0}(1+rh)^{\frac{1}{h}}=e^r$

$\lim_{h \to \infty}(1+\frac{1}{h})^h=e$

$\lim_{h \to 0}(1+h)^{\frac{1}{h}}=e$

对数函数和指数函数求导

对数函数和指数函数求导

阅读全文 »

三角函数的极限

小数的情况

${\lim_{x \to 0} \frac{sinx}{x}} = 1$

$\lim_{x \to 0} cosx = 1$

$\lim_{x \to 0} \frac{tanx}{x} = 1$

$\lim_{x \to 0} \frac{1-cosx}{x} = 0$

大数的情况

考虑极限$\lim_{x \to \infty}$

对于任意的x $-1 <= sinx <=1$ $-1 <=cosx <= 1$

应用三明治定理 $\lim_{x \to \infty} \frac{sinx}{x} = 0$

其他情况

考虑极限$\lim_{x \to \frac{\pi}{2}}\frac{cosx}{x-\frac{\pi}{2}}$
这次的三角函数是余弦, 且要在 π/2 的附近求值. 这既不是小数的情况也不是大数的情况, 因此很明显, 之前的情况都不适用.面对 x → a 的极限, 而a != 0 时, 有一个很好的一般原则, 那就是用 t = x − a作替换, 将问题转化为 t→0

阅读全文 »

连续性

我们先从一个函数是连续的, 这到底意味着什么开始. 正如我上面所说, 直觉上, 可以一笔画出连续函数的图像.

在一点处的连续

如果f(x)在a点连续,则必须满足以下三个条件:

  • 双侧极限${\lim_{x \to a} f(x)}$存在并且是有限的
  • 函数在点a处有定义,$f(a)$存在并且是有限的
  • 以上两个量相等,即: ${\lim_{x \to a} f(x) = f(x)}$

在一个区间上连续

函数f在[a, b] 上连续,需满足以下三个条件:

  • f在(a,b)的每一点都连续
  • 函数f在x = a处右连续,即 ${\lim_{x \to a^+} f(x)} = f(a)$
  • 函数f在x = b处左连续,即 ${\lim_{x \to b^-} f(x)} = f(b)$

★介值定理

阅读全文 »

基础知识

角度弧度换算

用弧度度量的角 = π/180 × 用度度量的角

用角度度量的角 = 180/π × 用弧度度量的角

sin cos tan csc sec cot

alt

sin(θ) = 对边/斜边

cos(θ) = 临边/斜边

tan(θ) = 对边/临边 = sin(θ)/cos(θ)

csc(θ) = 1/sin(θ)

sec(θ) = 1/cos(θ)

cot(θ) = 1/tan(θ)

常用三角函数速记表

alt

计算三角函数

阅读全文 »

奇函数与偶函数

  • 当对f定义域内所有的x都有f(-x) = -f(x)时,f是奇函数.奇函数的图像关于原点有180°的对称性.
  • 当对f定义域内所有的x都有f(-x) = f(x)时,f是偶函数,偶函数的图像关于y轴具有镜面对称性.

线性函数的图像

形如f(x) = mx + b的函数叫做线性函数,函数的图像为直线,斜率为m.

点斜式

如果已知直线通过点(x0, y0),斜率为m,则它的方程为 y - y0 = m(x - x0)

如果一条直线通过点 (x1, y1) 和 (x2, y2), 则它的斜率等于 (y2 − y1) / (x2 − x1)

常见函数及其图像

多项式

有许多函数是基于 x 的非负次幂建立起来的.你可以以 1、x、$x^2$、$x^3$等为基本项, 然后用实数同这些基本项做乘法, 最后把有限个这样的项加到一起.基本项 $x^n$ 的倍数叫作 $x^n$ 的系数.最大的幂指数n(该项系数不能为零) 叫作多项式的次数.

阅读全文 »

Functor

problem

This solution means that you’d have to rewrite a special version of every existing function you want to use in a Maybe! This greatly limits the usefulness of tools such as Maybe. It turns out Haskell has a type class that solves this problem, called Functor.

definition

Maybe is a member of the Functor type class. The Functor type class requires only one definition: fmap.
alt
_fmap provides an adapter_, Notice that we’re using <$>, which is a synonym for fmap (except it’s a binary operator rather than a function._This ability to transform the types of values inside a Maybe is the true power of the Functor type class._
alt

Though fmap is the official function name, in practice the binary operator <$> is used much more frequently
alt

Applicative

_the Applicative type class allows you to use functions that are inside a context, such as Maybe or IO, Functor is a superclass of Applicative._
alt
alt

The pure method

阅读全文 »

IO TYPES

Haskell has a special parameterized type called IO. Any value in an IO context must stay in this context. This prevents code that’s pure (meaning it upholds referential transparency and doesn’t change state) and code that’s necessarily impure from mixing.

IO types—dealing with an impure world

IO in Haskell is a parameterized type that’s similar to Maybe.The first thing they share in common is that they’re parameterized types of the same kind.The other thing that Maybe and IO have in common is that (unlike List or Map) they describe a context for their parameters rather than a container. The context for the IO type is that the value has come from an input/output operation.To keep Haskell code pure and predictable, you use the IO type to provide a context for data that may not behave the way all of the rest of your Haskell code does. IO actions aren’t functions.

Examples of IO actions

main doesn’t return any meaningful value; it simply performs an action. It turns out that main isn’t a function, because it breaks one of the fundamental rules of functions: it doesn’t return a value. Because of this, we refer to main as an IO action. IO actions work much like functions except they violate at least one of the three rules we established for functions early in the book. Some IO actions return no value, some take no input, and others don’t always return the same value given the same input.
alt

Do-notation

This do-notation allows you to treat IO types as if they were regular types. This also explains why some variables use let and others use <-. Variables assigned with <- allow you to act as though a type IO a is just of type a. You use let statements whenever you create variables that aren’t IO types.

<-

阅读全文 »

01. TYPE BASICS

in Haskell, you haven’t had to write down any information about the
type you’re using for any of your values. It turns out this is because Haskell has done it
for you! Haskell uses type inference to automatically determine the types of all values at
compile time based on the way they’re used! You don’t have to rely on Haskell to determine your types for you.

alt

list tuple function

alt

Functions with multiple arguments

why are type signatures this way? The reason is that behind the scenes in Haskell, all functions take only one argument. By rewriting makeAddress by using a series of nested lambda functions.

alt

Types for first-class functions

阅读全文 »
0%