



版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、空间直角坐标转换之仿射变换一、仿射变换仿射变换是空间直角坐标变换的一种, 它是一种二维坐标到二维坐标之间的线性变换,保持二维图形的“平直线”和“平行性” ,其可以通过一系列的原子变换的复合来实现,包括平移 (Translation)、缩放( Scale)、翻转( Flip)、旋转( Rotation)和剪切 (Shear)。此类变换可以用一个3× 3 的矩阵来表示,其最后一行为(0, 0, 1)。该变换矩阵将原坐标 (x, y)变换为新坐标 (x', y'),这里原坐标和新坐标皆视为最末一行为(1)的三维列向量,原列向量左乘变换矩阵得到新的列向量:x'm00
2、m01 m02 xm00*x+m01*y+m02y' = m10 m11 m12 y = m10*x+m11*y+m12100111如果将它写成按旋转、缩放、平移三个分量的复合形式,则其代数式如下:x = m00*x+m01*y+m02 ;y = m10*x+m11*y+m12 ;其示意图如下:几种典型的仿射变换:1.public static AffineTransform getTranslateInstance(double tx, double ty)平移变换,将每一点移动到(x+tx, y+ty),变换矩阵为:10tx01ty001(译注:平移变换是一种“刚体变换” ,rig
3、id-body transformation ,中学学过的物理,都知道啥叫“刚体”吧,就是不会产生形变的理想物体,平移当然不会改变二维图形的形状。同理,下面的“旋转变换”也是刚体变换,而“缩放”、“错切”都是会改变图形形状的。 )2.public static AffineTransform getScaleInstance(double sx, double sy)缩放变换,将每一点的横坐标放大(缩小)至sx 倍,纵坐标放大(缩小)至sy 倍,变换矩阵为:sx000sy00013.public static AffineTransform getShearInstance(double sh
4、x, double shy)剪切变换,变换矩阵为:1shx0shy10001相当于一个横向剪切与一个纵向剪切的复合1001shx0shy10010 001001(译注:“剪切变换”又称“错切变换” ,指的是类似于四边形不稳定性那种性质,街边小商店那种铁拉门都见过吧?想象一下上面铁条构成的菱形拉动的过程,那就是“错切”的过程。 )4.public static AffineTransform getRotateInstance(double theta)旋转变换,目标图形围绕原点顺时针旋转theta 弧度,变换矩阵为:cos(theta)-sin(theta)0sin(theta)cos(the
5、ta)00015.public static AffineTransform getRotateInstance(double theta, double x, double y)旋转变换,目标图形以 (x, y)为轴心顺时针旋转theta 弧度,变换矩阵为:cos(theta)-sin(theta)x-x*cos+y*sinsin(theta)cos(theta)y-x*sin-y*cos 001相当于两次平移变换与一次原点旋转变换的复合:10-xcos(theta)-sin(theta) 01 0 x01-ysin(theta)cos(theta)00 1y001 001 001二、仿射变
6、换四参数求解A、 C#自定义函数实现求解:1、求解旋转参数Rotaion:1 /<summary>23 /获取旋转角度45 /</summary>67/<param name="fromCoordPoint1">源点 1 </param>89/<param name="toCoordPoint1">目标点 1</param>1011/<param name="fromCoordPoint2">源点 2 </param>1213/<pa
7、ram name="toCoordPoint2">目标点 2</param>1415 /<returns> 返回旋转角度 </returns>1617 private double GetRotation(CoordPoint fromPoint1, CoordPoint toPoint1,CoordPointfromPoint2,CoordPoint toPoint2)1819 2021doublea = (toPoint2.Y - toPoint1.Y) * (fromPoint2.X - fromPoint1.X) - (to
8、Point2.X -toPoint1.X) * (fromPoint2.Y - fromPoint1.Y);2223doubleb = (toPoint2.X - toPoint1.X) * (fromPoint2.X - fromPoint1.X) + (toPoint2.Y- toPoint1.Y) * (fromPoint2.Y - fromPoint1.Y); 24 25 2627if (Math.Abs(b) > 0)2829returnMath.Tan(a / b);3031else3233returnMath.Tan( 0 );34352、求解缩放比例参数 (Scale):
9、1/<summary>23 /获取缩放比例因子45 /</summary>67/<param name="fromCoordPoint1">源点 1</param>89/<param name="toCoordPoint1">目标点 1</param>1011/<param name="fromCoordPoint2">源点 2</param>1213/<param name="toCoordPoint2">
10、目标点 2 </param>1415/<param name="rotation">旋转角度 </param>1617/<returns> 返回旋转因子 </returns>1819privatedouble GetScale(CoordPoint fromPoint1, CoordPoint toPoint1, CoordPoint fromPoint2, CoordPoint toPoint2,double rotation)2021 2223double a = toPoint2.X - toPoint1.X
11、;2425doubleb = (fromPoint2.X - fromPoint1.X) * Math.Cos(rotation) - (fromPoint2.Y - fromPoint1.Y)*Math.Sin(rotation);2627if (Math.Abs(b) > 0)2829returna / b;3031else3233return0 ;34353、求解 X 方向偏移距离参数( XTranslate):1/*/<summary>23/ 得到 X 方向偏移量45/</summary>67/<param name="fromCoordP
12、oint1"> 源点 1</param>89/<param name="toCoordPoint1"> 目标点 1</param>1011/<param name="rotation"> 旋转角度 </param>1213/<param name="scale"> 缩放因子 </param>1415/<returns> 返回 X 方向偏移量 </returns>1617 private double GetXTr
13、anslation(CoordPoint fromPoint1,CoordPoint toPoint1,double rotation,double scale)18192021return (toPoint1.X - scale * (fromPoint1.X * Math.Cos(rotation) - fromPoint1.Y *Math.Sin(rotation);222324254、求解 Y方向偏移距离参数 (YTranslate):1 /*/<summary>23/ 得到 Y 方向偏移量45/</summary>67/<param name="
14、;fromCoordPoint1"> 源点 1</param>89/<param name="toCoordPoint1"> 目标点 1</param>1011/<param name="rotation"> 旋转角度 </param>1213/<param name="scale"> 缩放因子 </param>1415/<returns> 返回 Y方向偏移量 </returns>1617private doub
15、le GetYTranslation(CoordPoint fromPoint1, CoordPoint toPoint1, doublerotation, double scale)18192021return (toPoint1.Y - scale * (fromPoint1.X * Math.Sin(rotation) + fromPoint1.Y *Math.Cos(rotation);2223B、C#+AE求解:1/<summary>23 / 从控制点定义仿射变换程式45/</summary>67/<param name="pFromPoint
16、s">源控制点 </param>89 /<param name="pToPoints"> 目标控制点 </param>1011/<returns> 返回变换定义 </returns>1213 private ITransformation GetAffineTransformation(IPoint pFromPoints, IPoint pToPoints)1415 1617 / 实例化仿射变换对象1819IAffineTransformation2D3GEN tAffineTransformat
17、ion = new AffineTransformation2DClass();2021 / 从源控制点定义参数2223tAffineTransformation.DefineFromControlPoints( ref pFromPoints, ref pToPoints);2425 / 查询引用接口2627ITransformation tTransformation = tAffineTransformationas ITransformation;2829 return tTransformation;3031三、空间对象转换求出参数后,再利用公式对相应坐标点进行转换是一件相对简单的事
18、件了。示例代码:/<summary>23 /转换空间点45 /</summary>67/<param name="pPoint">点 </param>89 /<returns> 返回转换后的点 </returns>1011private IGeometry TransformPoint(IPoint pPoint)1213 1415/*1617 / 说明:采用相似变换模型(四参数变换模型)1819 / X= ax + by + c2021 / Y=-bx + ay + d2223 /*2425doubleA = this .m_Scale * Math.Cos(this .m_RotationAngle);2627doubleB = this .m_Scale * Math.Sin(this .m
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 体育赛事用帐篷购销合同
- 双方夫妻离婚协议书
- 柚子水果购销合同
- 软件和信息技术服务外包合作协议
- 离婚协议书去哪弄
- 环境监测技术设备供应协议
- 绿色出行服务平台合作协议
- 砂石场劳动合同
- 农产品电商运营推广合同
- 房产中介公司劳动合同
- 定量包装商品培训
- 前言 马克思主义中国化时代化的历史进程与理论成果
- 无线电技术的起源与发展
- 数控铣床(加工中心)编程与操作完整版课件
- 感动中国人物-于敏
- 《中国特色社会主义法治理论》复习题集及解析共20篇
- 融资租赁租金计算表
- 数据结构英文教学课件:Chapter 5 Recursion
- 《中国—东盟自由贸易区概论》新版
- 降低钻孔灌注桩混凝土充盈系数QC
- 趣味历史(课堂PPT)
评论
0/150
提交评论