计算几何之向量的旋转 - momodi's Blog
SRM446 500
09上海赛区的H题

计算几何之向量的旋转

momodi posted @ Tue, 02 Feb 2010 09:53:55 +0800 in IAlgorithm with tags Computational Geometry , 3234 readers

 矩阵真的好优美,好多在数学中那些乘乘加加的操作,其本质都是矩阵。这些操作,往往都是把事物进行分解,对每一个基量进行操作,最后再把这些操作整合起来。

向量旋转,这个几何中的基本操作,可以相当优美的用矩阵来操作。究其原因,也是因为向量是多维的。用矩阵来操作,正是把向量分解开来,分别旋转,最后再进行整合。

看下面的矩阵

clip_image002[4]

这个是二维向量的旋转矩阵,它可以将一个向量逆时针旋转一个角度。

将其变形,变会得到二维向量的顺时针旋转的形式:

clip_image002[16]

这里要注意一种特殊的情况,就是当角度为90度的时候,sin和cos的结果只有1, 0, -1三种可能性。所以这个矩阵可以改写成特殊的形式,其意义在于用这样的旋转操作,不会产生精度问题。sin和cos的运算的精度是比较低的,能少用则尽量少用。在计算几何中的向量旋转操作,大部分都可以通过变形,只用到旋转90度,从而避免精度问题。

再来说一点就是,这些旋转矩阵都有一些特点,最明显的莫过于他们的行列式的值都是1。所以在验证正确性的时候,可以用这个操作。也正因为有这一个性质,所以向量才只会进行旋转,不会进行缩放。

 

三维向量的旋转矩阵:

 

clip_image002[30]

 

clip_image002[32]

clip_image002[30]

clip_image002[32]

clip_image002[34]

 

上面三个公式的旋转方向可以看成按右手定则。

来看第三个公式,这个公式是围绕Z轴,把X轴往Y轴方向移动。我们把拇指向上(表示Z轴),手指指向X轴,然后手指自然弯曲方向便是旋转方向。

其它两个公式也是类似。

其实第三个公式,去掉Z轴,就是开头讲的逆时针旋转的公式。

在其它方向上的旋转都可以由这三个矩阵组合而来。

围绕轴u = (ux, uy, uz)来旋转的矩阵代码如下:

double a[3][3] = {
        {SQR(ux) + (1 - SQR(ux)) * c, ux * uy * (1 - c) - uz * s, ux * uz * (1 - c) + uy * s},
        {ux * uy * (1 - c) + uz * s, SQR(uy) + (1 - SQR(uy)) * c, uy * uz * (1 - c) - ux * s},
        {ux * uz * (1 - c) - uy * s, uy * uz * (1 - c) + ux * s, SQR(uz) + (1 - SQR(uz)) * c}
    };

 

要注意这个ux * ux + uy * uy + uz * uz = 1

 

有一个比较有意思的问题就是,知道旋转矩阵之后,怎么来确定向量u呢?

我们做如下变形之后,可以得到:

Ru = Iu –> (R – I)u = 0

也就是说我们要找到一个非0的向量,使得他和一个矩阵乘起来得到一个空矩阵。这个问题可以用高斯消元来解决。实际上我们就是要解一个线性方程组。

 

Avatar_small
meidir said:
Fri, 08 Jul 2022 22:55:26 +0800

I really appreciate this post. I have been looking everywhere for this! Thank goodness I found it on Bing. You have made my day! Thx again macBook pro 回收

 

================

 

You’d superb suggestions there. I did a research about the issue and identified that likely almost anyone will agree with your web page. iphone回收價

 

=====================

 

Hi there, just became alert to your blog through Google, and found that it is really informative. I’m going to watch out for brussels. I’ll appreciate if you continue this in future. Lots of people will be benefited from your writing. Cheers! Aputure

Avatar_small
meidir said:
Wed, 20 Jul 2022 04:08:50 +0800

Thanks for your insight for your fantastic posting. I’m exhilarated I have taken the time to see this. It is not enough; I will visit your site every day. Woking taxi to Heathrow

Avatar_small
meidir said:
Sat, 23 Jul 2022 15:45:59 +0800

I like this website because so much useful material on here : tree services sacramento

Avatar_small
meidir said:
Mon, 25 Jul 2022 22:01:46 +0800

I like your post. It is good to see you verbalize from the heart and clarity on this important subject can be easily observed... Barba

Avatar_small
meidir said:
Fri, 29 Jul 2022 00:10:36 +0800

I like your post. It is good to see you verbalize from the heart and clarity on this important subject can be easily observed... Buy full spectrum cannabis oil

Avatar_small
meidir said:
Fri, 29 Jul 2022 20:28:23 +0800

I am glad to be one of many visitors on this outstanding web site thanks for posting . numero voyance gratuite


Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter