坐标旋转与曼哈顿距离与切比雪夫距离之间的转换

前置知识
s i n ( α ) = − s i n ( − α ) sin(\alpha)=-sin(-\alpha) sin(α)=sin(α)
c o s ( α ) = c o s ( − α ) cos(\alpha)=cos(-\alpha) cos(α)=cos(α)
s i n 2 ( α ) + c o s 2 ( α ) = 1 sin^2(\alpha)+cos^2(\alpha)=1 sin2(α)+cos2(α)=1
s i n ( α ) = c o s ( π 2 − α ) sin(\alpha)=cos(\frac{\pi}{2}-\alpha) sin(α)=cos(2πα)
和角公式:
c o s ( α − β ) = c o s ( α ) c o s ( β ) + s i n ( α ) s i n ( β ) cos(\alpha-\beta)=cos(\alpha)cos(\beta)+sin(\alpha)sin(\beta) cos(αβ)=cos(α)cos(β)+sin(α)sin(β)
证明:
做出一个单位圆,在圆上面取两个点, A ( c o s ( β ) , s i n ( β ) ) , B ( c o s ( α ) , s i n ( α ) ) A(cos(\beta),sin(\beta)),B(cos(\alpha),sin(\alpha)) A(cos(β),sin(β)),B(cos(α),sin(α))
那么它们的夹交 A O B AOB AOB就是 α − β \alpha-\beta αβ
勾股定理求 A B AB AB
A B 2 = ( c o s ( α ) − c o s ( β ) ) 2 + ( s i n ( α ) − s i n ( β ) ) 2 = 2 − c o s ( α ) c o s ( β ) − s i n ( α ) s i n ( β ) AB^2=(cos(\alpha)-cos(\beta))^2+(sin(\alpha)-sin(\beta))^2=2-cos(\alpha)cos(\beta)-sin(\alpha)sin(\beta) AB2=(cos(α)cos(β))2+(sin(α)sin(β))2=2cos(α)cos(β)sin(α)sin(β)
余弦定理求 A B AB AB 得, A B 2 = O A 2 + O B 2 − 2 c o s ( α − β ) O A ∗ O B = 2 − 2 ∗ c o s ( α − β ) AB^2=OA^2+OB^2-2cos(\alpha-\beta)OA*OB=2-2*cos(\alpha-\beta) AB2=OA2+OB22cos(αβ)OAOB=22cos(αβ)
所以有 c o s ( α − β ) = c o s ( α ) c o s ( β ) + s i n ( α ) s i n ( β ) cos(\alpha-\beta)=cos(\alpha)cos(\beta)+sin(\alpha)sin(\beta) cos(αβ)=cos(α)cos(β)+sin(α)sin(β)
同理有 c o s ( α + β ) = c o s ( α ) c o s ( β ) − s i n ( α ) s i n ( β ) cos(\alpha+\beta)=cos(\alpha)cos(\beta)-sin(\alpha)sin(\beta) cos(α+β)=cos(α)cos(β)sin(α)sin(β)

s i n ( α + β ) = c o s ( π 2 − α − β ) sin(\alpha+\beta)=cos(\frac{\pi}{2}-\alpha-\beta) sin(α+β)=cos(2παβ)
= c o s ( π 2 − α ) c o s ( β ) + s i n ( π 2 − α ) s i n ( β ) = s i n ( α ) c o s ( β ) + c o s ( α ) s i n ( β ) =cos(\frac{\pi}{2}-\alpha)cos(\beta)+sin(\frac{\pi}{2}-\alpha)sin(\beta)=sin(\alpha)cos(\beta)+cos(\alpha)sin(\beta) =cos(2πα)cos(β)+sin(2πα)sin(β)=sin(α)cos(β)+cos(α)sin(β)

s i n ( α − β ) = s i n ( α ) c o s ( β ) − c o s ( α ) s i n ( β ) sin(\alpha-\beta)=sin(\alpha)cos(\beta)-cos(\alpha)sin(\beta) sin(αβ)=sin(α)cos(β)cos(α)sin(β)


坐标旋转:
将坐标系顺时针转 α \alpha α 度,等价于将所有点逆时针转 α \alpha α
问题转变为已知 ( x , y ) (x,y) (x,y),求 ( x ′ , y ′ ) (x',y') (x,y),为 ( x , y ) (x,y) (x,y) 逆时针转 α \alpha α 度的点
( x , y ) (x,y) (x,y) x x x 的夹角为 A A A
那么 x ′ = ∣ R ∣ c o s ( A − α ) = ∣ R ∣ ( c o s ( A ) c o s ( α ) + s i n ( A ) s i n ( α ) ) = x ∗ c o s ( α ) + y ∗ s i n ( α ) x'=|R|cos(A-\alpha)=|R|(cos(A)cos(\alpha)+sin(A)sin(\alpha))=x*cos(\alpha)+y*sin(\alpha) x=Rcos(Aα)=R(cos(A)cos(α)+sin(A)sin(α))=xcos(α)+ysin(α)
y ′ = ∣ R ∣ s i n ( A − α ) = ∣ R ∣ ( s i n ( A ) c o s ( α ) − c o s ( A ) s i n ( α ) ) = y ∗ c o s ( α ) − x ∗ s i n ( α ) y'=|R|sin(A-\alpha)=|R|(sin(A)cos(\alpha)-cos(A)sin(\alpha))=y*cos(\alpha)-x*sin(\alpha) y=Rsin(Aα)=R(sin(A)cos(α)cos(A)sin(α))=ycos(α)xsin(α)


曼哈顿距离与切比雪夫距离的转换
曼哈顿转切比雪夫:
发现离原点,曼哈顿距离为 x x x 的点构成的集合刚好是一个偏了 4 5 o 45^{o} 45o 的正方形
把这个正方形转正,再扩大 2 \sqrt 2 2 倍,得到的新的正方形就是距原点切比雪夫距离为 x x x 的点的集合
于是就有 ( x , y ) (x,y) (x,y) 变到 2 ∗ ( x ∗ c o s ( 4 5 o ) + y ∗ s i n ( 4 5 o ) , y ∗ c o s ( 4 5 o ) − x ∗ s i n ( 4 5 o ) ) \sqrt 2*(x*cos(45^{o})+y*sin(45^{o}),y*cos(45^{o})-x*sin(45^{o})) 2 (xcos(45o)+ysin(45o),ycos(45o)xsin(45o))
也就是 ( x + y , x − y ) (x+y,x-y) (x+y,xy)
变回去就是 ( x + y 2 , x − y 2 ) (\frac{x+y}{2},\frac{x-y}{2}) (2x+y,2xy)

另一种理解方式:
曼哈顿: ∣ x 1 − x 2 ∣ + ∣ y 1 − y 2 ∣ |x_1-x_2|+|y_1-y_2| x1x2+y1y2
拆开看,有四种
x 1 − x 2 + y 1 − y 2 x_1-x_2+y_1-y_2 x1x2+y1y2
x 1 − x 2 − y 1 + y 2 x_1-x_2-y_1+y_2 x1x2y1+y2
− x 1 + x 2 + y 1 − y 2 -x_1+x_2+y_1-y_2 x1+x2+y1y2
− x 1 + y 2 − y 1 + y 2 -x_1+y_2-y_1+y_2 x1+y2y1+y2
一四所属同类, ∣ ( x 1 + y 1 ) − ( x 2 + y 2 ) ∣ |(x_1+y_1)-(x_2+y_2)| (x1+y1)(x2+y2)
二三所属同类, ∣ ( x 1 − y 1 ) − ( x 2 − y 2 ) ∣ |(x_1-y_1)-(x_2-y_2)| (x1y1)(x2y2)
曼哈顿距离取的是上述四种最大的一个
m a x ( ∣ ( x 1 + y 1 ) − ( x 2 + y 2 ) ∣ , ∣ ( x 1 − y 1 ) − ( x 2 − y 2 ) ∣ ) max(|(x_1+y_1)-(x_2+y_2)|,|(x_1-y_1)-(x_2-y_2)|) max((x1+y1)(x2+y2),(x1y1)(x2y2))
而这恰恰就是 ( x 1 + y 1 , y 1 − x 1 ) (x_1+y_1,y_1-x_1) (x1+y1,y1x1) ( x 2 + y 2 , y 2 − x 2 ) (x_2+y_2,y_2-x_2) (x2+y2,y2x2) 的切比雪夫距离

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FSYo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值