Matlab 以及相关知识

来源:互联网 发布:淘宝五星评价在哪里看 编辑:程序博客网 时间:2024/06/02 17:56

Problem Assignment

Assignment

Problem 3
(Use Matlab)
You have a box with 6 coins.
3 of the coins are weighted so that they come up heads with probability 0.3.
1 is weighted so that it comes up heads with probability 0.7.
2 are weighted so that they come up heads with probability 0.9.
A. What is the probability of heads, if you pick a coin at random and flip it?
B. Suppose that you pick a coin at random and flip it twice, and it comes up heads both times.
What are the posterior probabilities of the three different weights?
C. Suppose that you pick a coin at random and flip it twice and it comes up heads both times. What
is the probability that it will come up heads again if you flip it again?
D. Suppose that you pick a coin at random, flip it twice, and it comes up heads both times. You
now pick a different coin. What is the probability that it will come up heads?
E. Suppose that you pick a coin at random, flip it 10 times, and it comes up heads 6 times. What
now is the posterior probability of each of the weightings? Suppose that you flip it 20 times and it
comes up heads 12 times?
For each matrix


































M listed below, consider the product M · v
where v is the homogeneous coordinates of a point in two-space.

State:

  1. whether this operation carries out translation,
  2. rigid motion,
  3. scale transformation,
  4. invertable affine transformation,
  5. degenerate affine transformation;
  6. whether or not it leaves the origin fixed;
  7. whether or not it is a reflection.

Note that |<0.28, 0.96>| = 1. Given that fact, you should be able to do these by inspection, without putting pencil to paper, let alone running Matlab.





Whether Matrix 1 Rotation Matrix 2 Rotation Matrix 3 Reflection Matrix 4 Translation Translation No Yes Yes Yes Rigid motion No Yes No No Scale transformation No No No No Invertable affine transformation Yes Yes Yes No Degenerate affine transformation No No No No Leaves the origin fixed No Yes Yes No Reflection No No Yes No Determinant 1 1 -1 1



Whether Matrix 5 Matrix 6 Matrix 7 Matrix 8 Translation No No Yes No Rigid motion No No No No Scale transformation Yes No No No Invertable affine transformation Yes Yes Yes No Degenerate affine transformation No No No Yes Leaves the origin fixed Yes No Yes No Reflection No No No No Determinant 100 0.8432 -3 0










1. 旋转矩阵和反射矩阵都是正交矩阵
2. 旋转矩阵的行列式值为+1,反射矩阵的行列值为-1
3. Rotation是不变换原点的
4. Pure scale transformations是不变换原点的
5. Affine transformation 是不变换原点的,但是加上translation,就移动了原点
6. 畸变就是Degenerate affine transformation
6. 非畸变包括 rotation:det = 1,reflection:det = -1,scale:+—C^2






仿射变换
仿射变换2




Rigid motion 刚体运动

Scale transformation 标度变换法
标度变换就是放大或缩小也即码尺的变换,对分形来说用不同的码尺所测得的结果,有随码尺的变化而变化的,也有随码尺的变化而不变的。分形理论就是基于对事物在不同标度变换下的不变性。

Affine transformation matrix 仿射变换矩阵
仿射变换(Affine Transformation)

Affine Transformation是一种二维坐标到二维坐标之间的线性变换,保持二维图形的
“平直性”(译注:straightness,即变换后直线还是直线不会打弯,圆弧还是圆弧)
“平行性”(译注:parallelness,其实是指保二维图形间的相对位置关系不变,平行线还是平行线,相交直线的交角不变。)

image





仿射变换可以通过一系列的原子变换的复合来实现,
包括:平移(Translation)、缩放(Scale)、翻转(Flip)、旋转(Rotation)和剪切(Shear)。

image






仿射变换可以用下面公式表示:






image






具体到二维的仿射变换的计算如下:
image






平移变换(Translation)
将每一点移动到(x+tx, y+ty),变换矩阵为:

100010txty1

平移变换是一种“刚体变换”,rigid-body transformation,就是不会产生形变的理想物体。






缩放变换(Scale)
将每一点的横坐标放大(缩小)至sx倍,纵坐标放大(缩小)至sy倍,变换矩阵为:

Sx000Sy0001





剪切变换(Shear)
变换矩阵为:

1Shy0Shx10001

相当于一个横向剪切与一个纵向剪切的复合
image
效果





旋转变换(Rotation)
目标图形围绕原点顺时针旋转theta弧度,变换矩阵为:

cosθsinθ 0sinθcosθ0001

几何变换




















Programming Assignment

这里写图片描述

cube = { [0,0,0,0; 0,0,1,1; 0,1,1,0],  [1,1,1,1; 0,1,1,0; 0,0,1,1], [0,1,1,0; 0,0,0,0; 0,0,1,1],  [0,0,1,1; 1,1,1,1; 0,1,1,0], [0,0,1,1; 0,1,1,0; 0,0,0,0],  [0,1,1,0; 0,0,1,1; 1,1,1,1] };




Function DrawRotatedPolydedron

function DrawRotatedPolyhedron(M,P)%   Apply the Matrix M to each of the points in P%   Generating a new polyhedron P'new_P   =   {};             %   生成一个新的new_P 矩阵组n       =   length(P);      %   得出一个矩阵组的个数,如果用cube, n = 6visible =   [];             %   生成一个新的矩阵,visibleA       =   pi/4;B       =   pi/4;C       =   0;M       =   EulerRotation(A,B,C);                            %   生成一个欧拉角矩阵,生成过程下面有详细解释for i   =   1:n      face    =   M*P{i};      a       =   face(:,1);      b       =   face(:,2);      c       =   face(:,3);      normal  =   cross(c-b,a-b);                                    if normal(3)<=0                                    visible=[visible,i];                                    end    new_P{i}  =   face;end% compute the outward normal to each face% exclude any face whose normal has a positive z-component% choose any three consecutive vertices of the face a,b,c; % the cross-product (c − b) × (a − b) is the outward normal.







以P1为例
这里可以得到face组

face的第一列是a,第二列是b,第三列是c
求出face的法向量,叉乘得到一个normal,normal的z值如果为正,就舍弃掉




n_visible   =   length(visible);N           =   100;                    % 不知道为什么要Nfigure;                                 % 创建图片窗口hold;                                   % 使用hold on指令后,此后添加的一系列plot曲线将叠加在前一个图上for i=1:n_visible    face    =   new_P{visible(i)};      % 在cube的例子里,有3个visible,所以face就有3个new_P的成分    plotFace(face);       % length(face)就是 face,也就是3

以cube为例,face有3个visible元素,第1个就是new_P{visible(1)=2}
所以face = new_P{visible(1)=2} 依然是一个 [3x4 double]




下面进行作图

>> face=new_P{visible(1)};>> faceface =    0.7071    0.0000    0.0000    0.7071    0.5000    1.0000    1.7071    1.2071   -0.5000   -1.0000   -0.2929    0.2071>> proj_face=face(1:2,:); >> proj_faceproj_face =    0.7071    0.0000    0.0000    0.7071    0.5000    1.0000    1.7071    1.2071>> proj_face=[proj_face,proj_face(:,1)];>> proj_faceproj_face =    0.7071    0.0000    0.0000    0.7071    0.7071    0.5000    1.0000    1.7071    1.2071    0.5000>> plot(proj_face(1,:),proj_face(2,:))

删除了z轴坐标,自然就变成了xoy平面的图像
然后把坐标全部画出来,必须要有5组,不然图像不闭合





plotFace(face);

function plotFace(face)n           =   length(face);proj_face   =   face(1:2,:); proj_face   =   [proj_face,proj_face(:,1)];plot(proj_face(1,:),proj_face(2,:))

循环3次,把三个new_P做一次就生成了上图


下面是在面上生成椭圆
Compute the center o of the face as the average of the vertices of the face
在每个面找中心点,我的思路是两个对边找中点连起来

Choose a radius r as half the distance from o to the nearest of the edges (use the formula for the distance from a point to an edge discussed in class)
找到o到最近边的距离的1/2作为半径

Find two orthogonal vectors ~u, ~v in the plane of the face. (If a, b, c are vertices in the face, then you can choose dir(b − a) as one and the perpendicular from c to line ab as the other.)

– Compute points on the circle in 3D as o + r cos(2πt/N)~u + r sin(2πt/N)~v for t = 0 … N.
– Project these points onto the x − y plane by ignoring the z-coordinate, and connect the
points to plot the ellipse

n_face  =   size(face,2);               %center  =   sum(face,2)/ n_face;        % 求出了中点 
function d          =   CalcDistance(P,Q1,Q2)         d          =   norm(cross(Q2-Q1,P-Q1))/norm(Q2-Q1);end
function min_dis    =   MinDistance(center,face)         aug_face   =   [face,face(:,1)];                n   =   size(aug_face,2);                dis =   [];    for i=1:n-1               dis  =[dis,CalcDistance(center,aug_face(:,i),aug_face(:,i+1))];    end            min_dis =   min(dis);end


























这里有矩阵的表达方法

111xyzx2y2z2

三维空间中刚体的旋转

绕x,y,或z轴旋转θ的矩阵为:

R_{x}(\theta)=

1000cosθsinθ0sinθcosθ

R_{y}(\theta)=
cosθ0sinθ010sinθ0cosθ

R_{z}(\theta)=
cosθsinθ0sinθcosθ0001

所以,绕任意轴旋转的矩阵为
Rx(−p)⋅Ry(−q)⋅Rz(θ)⋅Ry(q)⋅Rx(p)
这表示:

  1. 绕x轴旋转角度p使指定的旋转轴在xz平面上
  2. 绕y轴旋转角度q使指定的旋转轴与z轴重合
  3. 绕z轴旋转角度θ
  4. 绕y轴旋转角度-q
  5. 绕x轴旋转角度-p

其中,p和q的值需要用i,j,k计算出来。

Euler angles 欧拉角

这里写图片描述

Z-Y-Z Euler Angles

第一次先围绕z轴旋转,得到下图
这里写图片描述

Rot(z, Φ)
然后旋转围绕y轴旋转,得到下图

Rot(y,θ )
这里写图片描述

最后再围绕z轴再做一次旋转,得到下图
Rot(z, ψ)
这里写图片描述

问题是
这几个是linearly independent吗?

答案是的
θ=0,特殊,就是singular case
会导致两次z旋转colinear,三个axis不在线性独立

Determination of Euler Angles
这里写图片描述

R = Rot(z, Φ) × Rot(y,θ ) × Rot(z, ψ)
这里写图片描述
欧拉角也可以描述三维刚体旋转,它将刚体绕过原点的轴(i,j,k)旋转θ,分解成三步(蓝色是起始坐标系,而红色的是旋转之后的坐标系。)。

  1. 绕z轴旋转α,使x轴与N轴重合,N轴是旋转前后两个坐标系x-y平面的交线
  2. 绕x轴(也就是N轴)旋转β,使z轴与旋转后的z轴重合
  3. 绕z轴旋转γ,使坐标系与旋转后的完全重合

资料

三维旋转:旋转矩阵,欧拉角,四元数
Euler Angels YouTube

原创粉丝点击