/*
* 矩阵基本变换,旋转类Rotate
** 编制人: $ource
* 修改版次及创建时间:0版完成版(2024年8月26日)
* 修改内容及时间:无
* 待完善问题:无
* 内容说明:旋转是矩阵基本功能,实现了“组合矩阵*旋转矩阵”、“移动矩阵*旋转矩阵”、“旋转矩阵*旋转矩阵”、“旋转矩阵*组合矩阵”、“旋转矩阵*移动矩阵”的运算符重载。旋转矩阵格式如下。
1 0 0
0 cos(a) sin(a)
0 -sin(a) cos(a)
*/
use super::angle::Angle;
pub type Rotate=Matrix<Zero,Zero,f64,f64,f64,f64>;
impl Rotate{
pub fn new(xx:f64,xy:f64,yx:f64,yy:f64)->Rotate{
Rotate{
m01:Zero{}, m02:Zero{},
m11:xx, m12:xy,
m21:yx, m22:yy
}
}
pub fn from(ang:Angle)->Rotate{
let ang_x=ang.unit_x();
let ang_y=ang.unit_y();
Rotate::new(ang_x,ang_y,-ang_y,ang_x)
}
}
impl Mul<Rotate> for M2D{//组合矩阵*旋转矩阵
type Output = M2D;
fn mul(self, tm:Rotate) ->M2D{
M2D{
m01:self.m01 * tm.m11 + self.m02 * tm.m21 ,m02:self.m01 * tm.m12 + self.m02 * tm.m22,
m11:self.m11 * tm.m11 + self.m12 * tm.m21 ,m12:self.m11 * tm.m12 + self.m12 * tm.m22,
m21:self.m21 * tm.m11 + self.m22 * tm.m21 ,m22:self.m21 * tm.m12 + self.m22 * tm.m22
}
}
}
impl Mul<Rotate> for Move{//移动矩阵*旋转矩阵
type Output = M2D;
fn mul(self, tm:Rotate) ->M2D{
M2D{
m01:self.m01 * tm.m11 + self.m02 * tm.m21,m02:self.m01 * tm.m12 + self.m02 * tm.m22,
m11:tm.m11 ,m12:tm.m12,
m21:tm.m21 ,m22:tm.m22
}
}
}
impl Mul<Rotate> for Rotate{//旋转矩阵*旋转矩阵
type Output = Rotate;
fn mul(self, tm:Rotate) ->Rotate{
Rotate::new(
self.m11 * tm.m11 + self.m12 * tm.m21, self.m11 * tm.m12 + self.m12 * tm.m22,
self.m21 * tm.m11 + self.m22 * tm.m21, self.m21 * tm.m12 + self.m22 * tm.m22
)
}
}
impl Mul<M2D> for Rotate{//旋转矩阵*组合矩阵
type Output = M2D;
fn mul(self, tm:M2D) ->M2D{
M2D{
m01:tm.m01 , m02:tm.m02,
m11:self.m11 * tm.m11 + self.m12 * tm.m21, m12:self.m11 * tm.m12 + self.m12 * tm.m22,
m21:self.m21 * tm.m11 + self.m22 * tm.m21 ,m22:self.m21 * tm.m12 + self.m22 * tm.m22
}
}
}
impl Div<Move> for Rotate{//旋转矩阵*移动矩阵
type Output = M2D;
fn div(self, tm:Move) ->M2D{
M2D{
m01:tm.m01, m02:tm.m02,
m11:self.m11, m12:self.m12,
m21:self.m21,m22:self.m22
}
}
}
08-25
311
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-17
582
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)