生活随笔
收集整理的這篇文章主要介紹了
E - Rotate and Flip(线性代数矩阵坐标变换)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
E - Rotate and Flip
順時針
[010?100001][xy1]=[y?x1]\begin{bmatrix} 0 & 1 & 0\\ -1&0&0\\0 &0&1 \end{bmatrix}\begin{bmatrix} x\\y\\1 \end{bmatrix}=\begin{bmatrix} y\\-x\\1 \end{bmatrix}???0?10?100?001???????xy1????=???y?x1????
逆時針
[0?10100001][xy1]=[?yx1]\begin{bmatrix} 0 & -1 & 0\\ 1&0&0\\0 &0&1 \end{bmatrix}\begin{bmatrix} x\\y\\1 \end{bmatrix}=\begin{bmatrix} -y\\x\\1 \end{bmatrix}???010??100?001???????xy1????=????yx1????
關于x=px=px=p對稱
[?102p010001][xy1]=[2p?xy1]\begin{bmatrix} -1 & 0 & 2p\\ 0&1&0\\0 &0&1 \end{bmatrix}\begin{bmatrix} x\\y\\1 \end{bmatrix}=\begin{bmatrix} 2p-x\\y\\1 \end{bmatrix}????100?010?2p01???????xy1????=???2p?xy1????
關于y=py=py=p對稱
[1000?1?2p001][xy1]=[x2p?y1]\begin{bmatrix} 1 & 0 & 0\\ 0&-1&-2p\\0 &0&1 \end{bmatrix}\begin{bmatrix} x\\y\\1 \end{bmatrix}=\begin{bmatrix} x\\2p-y\\1 \end{bmatrix}???100?0?10?0?2p1???????xy1????=???x2p?y1????
注意:左乘矩陣
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<random>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
using namespace std
;
typedef long long ll
;
typedef unsigned long long ull
;
typedef pair
<ll
,int> pli
;
typedef pair
<int,int> pii
;
const ll mod
=1e9+7;
const int N
=200010;
int sz
;
struct node
{ll m
[3][3];node(){memset(m
,0,sizeof m
);}node
operator *(const node
& o
)const{node res
;for(int i
=0;i
<sz
;i
++)for(int j
=0;j
<sz
;j
++)for(int k
=0;k
<sz
;k
++)res
.m
[i
][j
]+=m
[i
][k
]*o
.m
[k
][j
];return res
;}
}q
[N
];
void update(int k
,int op
,int p
)
{if(op
==0){q
[k
].m
[0][0]=q
[k
].m
[1][1]=q
[k
].m
[2][2]=1;return;}else if(op
==1)q
[k
].m
[0][1]=1,q
[k
].m
[1][0]=-1,q
[k
].m
[2][2]=1;else if(op
==2)q
[k
].m
[0][1]=-1,q
[k
].m
[1][0]=1,q
[k
].m
[2][2]=1;else if(op
==3){q
[k
].m
[0][0]=-1,q
[k
].m
[0][2]=2*p
;q
[k
].m
[1][1]=q
[k
].m
[2][2]=1;}else{q
[k
].m
[1][1]=-1,q
[k
].m
[1][2]=2*p
;q
[k
].m
[0][0]=q
[k
].m
[2][2]=1;}q
[k
]=q
[k
]*q
[k
-1];
}
ll x
[N
],y
[N
];
void print(int k
,int i
)
{ll x0
=q
[k
].m
[0][0]*x
[i
]+q
[k
].m
[0][1]*y
[i
]+q
[k
].m
[0][2];ll y0
=q
[k
].m
[1][0]*x
[i
]+q
[k
].m
[1][1]*y
[i
]+q
[k
].m
[1][2];cout
<<x0
<<' '<<y0
<<'\n';
}
int main()
{IO
;int T
=1;while(T
--){sz
=3;int n
,m
,qc
;cin
>>n
;for(int i
=1;i
<=n
;i
++) cin
>>x
[i
]>>y
[i
];cin
>>m
;update(0,0,0);int op
,p
=0;for(int i
=1;i
<=m
;i
++){cin
>>op
;if(op
==3||op
==4) cin
>>p
;update(i
,op
,p
);}cin
>>qc
;while(qc
--){int a
,b
;cin
>>a
>>b
;print(a
,b
);}}return 0;
}
這《線性代數》真的白學了,最基本的東西都回憶不起來
總結
以上是生活随笔為你收集整理的E - Rotate and Flip(线性代数矩阵坐标变换)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。