定点绕定轴旋转

通过两个已知点,绕定轴旋转360次,每次旋转一度,获得360个点,一次相连,可以获得一个近似圆。
网上找的公式基本都是左手坐标系下的选择公式,故而进行了多次坐标转换

1、3.2版本

public static List<Vector3d> Translate(List<Vector3> list)
        {
            List<Vector3d> zuoshou = new List<Vector3d>();//存左手坐标系下的各点坐标
            List<Vector3d> shijiezuobiao = new List<Vector3d>();//存世界坐标系下的各点坐标
            List<Vector3d> jieguoweidu = new List<Vector3d>();//存世界坐标转换过来的经纬度坐标
            List<Vector3d> zuizhong = new List<Vector3d>();//存经纬度不变,高程设为新值的经纬度坐标
            //由双击球体获取点位置和球心三点生成平面,过圆心垂直此平面的法向量,作为旋转轴
            Vector3 p1 = new Vector3(list[0].X, list[0].Z, list[0].Y);
            Vector3 p2 = new Vector3(list[1].X, list[1].Z, list[1].Y);
            Vector3 xuanzhuanzhou = new Vector3();
            xuanzhuanzhou.X = 1;
            xuanzhuanzhou.Y = (p1.X * p2.Z - p2.X * p1.Z) / (p1.Z * p2.Y - p2.Z * p1.Y);
            xuanzhuanzhou.Z = (p1.X * p2.Y - p2.X * p1.Y) / (p1.Y * p2.Z - p1.Z * p2.Y);
            xuanzhuanzhou.Normalize();
            zuoshou.Add(new Vector3d(list[0].X, list[0].Z, list[0].Y));

            double x11, x12, x13, x21, x22, x23, x31, x32, x33;

            Vector3d pos = new Vector3d();
            int iii = 1;
            for (int i = 0; i < 360; i++)
            {
                jiaodu = Math.PI * iii / 180;
                x11 = Math.Cos(jiaodu) + xuanzhuanzhou.X * xuanzhuanzhou.X * (1 - Math.Cos(jiaodu));
                x12 = xuanzhuanzhou.X * xuanzhuanzhou.Y * (1 - Math.Cos(jiaodu)) - xuanzhuanzhou.Z * Math.Sin(jiaodu);
                x13 = xuanzhuanzhou.X * xuanzhuanzhou.Z * (1 - Math.Cos(jiaodu)) + xuanzhuanzhou.Y * Math.Sin(jiaodu);

                x21 = xuanzhuanzhou.X * xuanzhuanzhou.Y * (1 - Math.Cos(jiaodu)) + xuanzhuanzhou.Z * Math.Sin(jiaodu);
                x22 = Math.Cos(jiaodu) + xuanzhuanzhou.Y * xuanzhuanzhou.Y * (1 - Math.Cos(jiaodu));
                x23 = xuanzhuanzhou.Y * xuanzhuanzhou.Z * (1 - Math.Cos(jiaodu)) - xuanzhuanzhou.X * Math.Sin(jiaodu);

                x31 = xuanzhuanzhou.X * xuanzhuanzhou.Z * (1 - Math.Cos(jiaodu)) - xuanzhuanzhou.Y * Math.Sin(jiaodu);
                x32 = xuanzhuanzhou.Y * xuanzhuanzhou.Z * (1 - Math.Cos(jiaodu)) + xuanzhuanzhou.X * Math.Sin(jiaodu);
                x33 = Math.Cos(jiaodu) + xuanzhuanzhou.Z * xuanzhuanzhou.Z * (1 - Math.Cos(jiaodu));

                double posX = zuoshou[0].X * x11 + zuoshou[0].Y * x21 + zuoshou[0].Z * x31;
                double posY = zuoshou[0].X * x12 + zuoshou[0].Y * x22 + zuoshou[0].Z * x32;
                double posZ = zuoshou[0].X * x13 + zuoshou[0].Y * x23 + zuoshou[0].Z * x33;

                zuoshou.Add(new Vector3d(posX, posY, posZ));
                iii++;
            }
            for (int i = 0; i < zuoshou.Count; i++)//将左手坐标系下点转换为世界坐标系下点坐标
            {
                shijiezuobiao.Add(new Vector3d(zuoshou[i].X, zuoshou[i].Z, zuoshou[i].Y));
            }
            for (int ii = 0; ii < shijiezuobiao.Count; ii++)//将世界坐标转换为经纬度坐标
            {
                jieguoweidu.Add(new Vector3d(ConvertWorldPositionToGeoPosition(shijiezuobiao[ii])));
            }
            for (int iiii = 0; iiii < jieguoweidu.Count; iiii++)//设置轨道圆的半径,值离地面高度
            {
                zuizhong.Add(new Vector3d(jieguoweidu[iiii].X, jieguoweidu[iiii].Y, 1000000));
            }
            return zuizhong;
        }

2、5.0版本

        /// </summary>
        /// 计算点对,返回结果保存经纬度
        /// </summary>
        /// <param name="list">旋转轴起始点世界坐标,两个点</param>
        /// <param name="Clist">中间需要旋转的点的世界坐标</param>
        /// <param name="jiaodu">旋转角度</param>
        /// <returns></returns>
        public static List<PointList> Translate(List<Vector3> listtt, List<Vector3> Clisttt, double jiaodu)
        {
            //将世界坐标转为左手坐标
            var list = new List<Vector3>();
            var Clist = new List<Vector3>();
            for (int i = 0; i < listtt.Count; i++)
            {
                list.Add(new Vector3(listtt.ElementAt(i).X, listtt.ElementAt(i).Z, listtt.ElementAt(i).Y));
            }
            for (int i = 0; i < Clisttt.Count; i++)
            {
                Clist.Add(new Vector3(Clisttt.ElementAt(i).X, Clisttt.ElementAt(i).Z, Clisttt.ElementAt(i).Y));
            }

            var LeftList = new List<PointList>();//存左手坐标系下的各点坐标
            var WorldList = new List<PointList>();//存世界坐标系下的各点坐标
            var LatLonList = new List<PointList>();//存世界坐标转换过来的经纬度坐标,弧度制
            var RetureList = new List<PointList>();//存返回坐标,经纬度,高

            Vector3 p1 = new Vector3(list[0].X, list[0].Y, list[0].Z);
            Vector3 p2 = new Vector3(list[1].X, list[1].Y, list[1].Z);
            Vector3 xuanzhuanzhou = new Vector3();

            double x11, x12, x13, x21, x22, x23, x31, x32, x33;
            double x111, x121, x131, x211, x221, x231, x311, x321, x331;
            jiaodu = System.Math.PI * jiaodu / 180;
            var jiaodu2 = -jiaodu;

            //CList最少存储2
            //if (Clist.Count == 1)
            //{

            //}
            for (int i = 0; i < Clist.Count; i++)
            {
                #region //确定旋转轴
                if (i == 0)
                {
                    xuanzhuanzhou.X = Clist.ElementAt(1).X - Clist.ElementAt(0).X;
                    xuanzhuanzhou.Y = Clist.ElementAt(1).Y - Clist.ElementAt(0).Y;
                    xuanzhuanzhou.Z = Clist.ElementAt(1).Z - Clist.ElementAt(0).Z;
                    var mo = System.Math.Sqrt(xuanzhuanzhou.X * xuanzhuanzhou.X + xuanzhuanzhou.Y * xuanzhuanzhou.Y + xuanzhuanzhou.Z * xuanzhuanzhou.Z);
                    xuanzhuanzhou.X = xuanzhuanzhou.X / mo;
                    xuanzhuanzhou.Y = xuanzhuanzhou.Y / mo;
                    xuanzhuanzhou.Z = xuanzhuanzhou.Z / mo;
                }
                else if (i == Clist.Count - 1)
                {
                    xuanzhuanzhou.X = Clist.ElementAt(Clist.Count - 2).X - Clist.ElementAt(Clist.Count - 1).X;
                    xuanzhuanzhou.Y = Clist.ElementAt(Clist.Count - 2).Y - Clist.ElementAt(Clist.Count - 1).Y;
                    xuanzhuanzhou.Z = Clist.ElementAt(Clist.Count - 2).Z - Clist.ElementAt(Clist.Count - 1).Z;
                    var mo = System.Math.Sqrt(xuanzhuanzhou.X * xuanzhuanzhou.X + xuanzhuanzhou.Y * xuanzhuanzhou.Y + xuanzhuanzhou.Z * xuanzhuanzhou.Z);
                    xuanzhuanzhou.X = xuanzhuanzhou.X / mo;
                    xuanzhuanzhou.Y = xuanzhuanzhou.Y / mo;
                    xuanzhuanzhou.Z = xuanzhuanzhou.Z / mo;
                }
                else
                {
                    xuanzhuanzhou.X = Clist.ElementAt(i - 1).X - Clist.ElementAt(i + 1).X;
                    xuanzhuanzhou.Y = Clist.ElementAt(i - 1).Y - Clist.ElementAt(i + 1).Y;
                    xuanzhuanzhou.Z = Clist.ElementAt(i - 1).Z - Clist.ElementAt(i + 1).Z;
                    var mo = System.Math.Sqrt(xuanzhuanzhou.X * xuanzhuanzhou.X + xuanzhuanzhou.Y * xuanzhuanzhou.Y + xuanzhuanzhou.Z * xuanzhuanzhou.Z);
                    xuanzhuanzhou.X = xuanzhuanzhou.X / mo;
                    xuanzhuanzhou.Y = xuanzhuanzhou.Y / mo;
                    xuanzhuanzhou.Z = xuanzhuanzhou.Z / mo;
                }

                #endregion
                #region 坐标计算
                Vector3 pos = new Vector3();
                x11 = System.Math.Cos(jiaodu) + xuanzhuanzhou.X * xuanzhuanzhou.X * (1 - System.Math.Cos(jiaodu));
                x12 = xuanzhuanzhou.X * xuanzhuanzhou.Y * (1 - System.Math.Cos(jiaodu)) - xuanzhuanzhou.Z * System.Math.Sin(jiaodu);
                x13 = xuanzhuanzhou.X * xuanzhuanzhou.Z * (1 - System.Math.Cos(jiaodu)) + xuanzhuanzhou.Y * System.Math.Sin(jiaodu);
                x21 = xuanzhuanzhou.X * xuanzhuanzhou.Y * (1 - System.Math.Cos(jiaodu)) + xuanzhuanzhou.Z * System.Math.Sin(jiaodu);
                x22 = System.Math.Cos(jiaodu) + xuanzhuanzhou.Y * xuanzhuanzhou.Y * (1 - System.Math.Cos(jiaodu));
                x23 = xuanzhuanzhou.Y * xuanzhuanzhou.Z * (1 - System.Math.Cos(jiaodu)) - xuanzhuanzhou.X * System.Math.Sin(jiaodu);
                x31 = xuanzhuanzhou.X * xuanzhuanzhou.Z * (1 - System.Math.Cos(jiaodu)) - xuanzhuanzhou.Y * System.Math.Sin(jiaodu);
                x32 = xuanzhuanzhou.Y * xuanzhuanzhou.Z * (1 - System.Math.Cos(jiaodu)) + xuanzhuanzhou.X * System.Math.Sin(jiaodu);
                x33 = System.Math.Cos(jiaodu) + xuanzhuanzhou.Z * xuanzhuanzhou.Z * (1 - System.Math.Cos(jiaodu));
                double posX = Clist.ElementAt(i).X * x11 + Clist.ElementAt(i).Y * x21 + Clist.ElementAt(i).Z * x31;
                double posY = Clist.ElementAt(i).X * x12 + Clist.ElementAt(i).Y * x22 + Clist.ElementAt(i).Z * x32;
                double posZ = Clist.ElementAt(i).X * x13 + Clist.ElementAt(i).Y * x23 + Clist.ElementAt(i).Z * x33;

                x111 = System.Math.Cos(jiaodu2) + xuanzhuanzhou.X * xuanzhuanzhou.X * (1 - System.Math.Cos(jiaodu2));
                x121 = xuanzhuanzhou.X * xuanzhuanzhou.Y * (1 - System.Math.Cos(jiaodu2)) - xuanzhuanzhou.Z * System.Math.Sin(jiaodu2);
                x131 = xuanzhuanzhou.X * xuanzhuanzhou.Z * (1 - System.Math.Cos(jiaodu2)) + xuanzhuanzhou.Y * System.Math.Sin(jiaodu2);
                x211 = xuanzhuanzhou.X * xuanzhuanzhou.Y * (1 - System.Math.Cos(jiaodu2)) + xuanzhuanzhou.Z * System.Math.Sin(jiaodu2);
                x221 = System.Math.Cos(jiaodu2) + xuanzhuanzhou.Y * xuanzhuanzhou.Y * (1 - System.Math.Cos(jiaodu2));
                x231 = xuanzhuanzhou.Y * xuanzhuanzhou.Z * (1 - System.Math.Cos(jiaodu2)) - xuanzhuanzhou.X * System.Math.Sin(jiaodu2);
                x311 = xuanzhuanzhou.X * xuanzhuanzhou.Z * (1 - System.Math.Cos(jiaodu2)) - xuanzhuanzhou.Y * System.Math.Sin(jiaodu2);
                x321 = xuanzhuanzhou.Y * xuanzhuanzhou.Z * (1 - System.Math.Cos(jiaodu2)) + xuanzhuanzhou.X * System.Math.Sin(jiaodu2);
                x331 = System.Math.Cos(jiaodu2) + xuanzhuanzhou.Z * xuanzhuanzhou.Z * (1 - System.Math.Cos(jiaodu2));
                double posX1 = Clist.ElementAt(i).X * x111 + Clist.ElementAt(i).Y * x211 + Clist.ElementAt(i).Z * x311;
                double posY1 = Clist.ElementAt(i).X * x121 + Clist.ElementAt(i).Y * x221 + Clist.ElementAt(i).Z * x321;
                double posZ1 = Clist.ElementAt(i).X * x131 + Clist.ElementAt(i).Y * x231 + Clist.ElementAt(i).Z * x331;
                #endregion

                if(i==0)
                { LeftList.Add(new PointList { StartPoint = new Vector3(posX1, posY1, posZ1), EndPoint = new Vector3(posX, posY, posZ) }); }
                else
                { LeftList.Add(new PointList { StartPoint = new Vector3(posX, posY, posZ), EndPoint = new Vector3(posX1, posY1, posZ1) }); }

            }

            #region 坐标变换
            //将左手坐标系下点转换为世界坐标系下点坐标
            for (int i = 0; i < LeftList.Count; i++)
            {
                WorldList.Add(new PointList
                {
                    StartPoint = new Vector3(LeftList.ElementAt(i).StartPoint.X, LeftList.ElementAt(i).StartPoint.Z, LeftList.ElementAt(i).StartPoint.Y),
                    EndPoint = new Vector3(LeftList.ElementAt(i).EndPoint.X, LeftList.ElementAt(i).EndPoint.Z, LeftList.ElementAt(i).EndPoint.Y)
                });
            }

            // 将世界坐标转换为经纬度坐标
            for (int i = 0; i < WorldList.Count; i++)
            {
                var TempStart = new Vector3();
                var TempEnd = new Vector3();
                TempStart = SpatialCalculator.CartesianToSpherical(WorldList.ElementAt(i).StartPoint);
                TempEnd = SpatialCalculator.CartesianToSpherical(WorldList.ElementAt(i).EndPoint);
                LatLonList.Add(new PointList { StartPoint = TempStart, EndPoint = TempEnd });
            }

            //将弧度转换为度,并调整存储位置
            for (int i = 0; i < LatLonList.Count; i++)
            {
                var TempStart = new Vector3();
                var TempEnd = new Vector3();

                ///LatLonList里面,X,Y,Z分别存储的是高,纬度,经度.绘制数据源里面的点需要经纬高,这里需要重新变换赋值。
                TempStart.X = (LatLonList.ElementAt(i).StartPoint.Z * 180) / System.Math.PI;
                TempStart.Y = (LatLonList.ElementAt(i).StartPoint.Y * 180) / System.Math.PI;
                TempStart.Z = LatLonList.ElementAt(i).StartPoint.X - 6378137;
                TempEnd.X = (LatLonList.ElementAt(i).EndPoint.Z * 180) / System.Math.PI;
                TempEnd.Y = (LatLonList.ElementAt(i).EndPoint.Y * 180) / System.Math.PI;
                TempEnd.Z = LatLonList.ElementAt(i).EndPoint.X - 6378137;

                TempStart.Z = listenaltitude.GetAltitude(TempStart.Y, TempStart.X);
                TempEnd.Z = listenaltitude.GetAltitude(TempEnd.Y, TempEnd.X);

                RetureList.Add(new PointList { StartPoint = TempStart, EndPoint = TempEnd });

            }

            LeftList.Clear();
            WorldList.Clear();
            LatLonList.Clear();
            #endregion
            return RetureList;
        }
         

原文地址:https://www.cnblogs.com/zwcoding/p/9255280.html

时间: 2024-11-05 22:01:19

定点绕定轴旋转的相关文章

绕任意轴旋转的矩阵推导总结

前言 常用的几何变换中旋转是较为复杂的一种,最近看<Physically Based Rendering, Second Edition: From Theory To Implementation>一书涉及绕任意轴旋转的实现,也给出了大体思路,但具体的推导过程及最后的旋转矩阵并未直接地给出,故根据参考Animated CGEM: Rotation About an Arbitrary Axis总结(欢迎指正). (一)基础 1.点乘与叉乘 点乘(dot)亦称作内积或数量积,如图,a·b =

cocos2dx--- Node 绕Y轴旋转

step += 5; float ra = (float) CC_DEGREES_TO_RADIANS(step); float i = sinf(ra) * pNode->getCamera()->getZEye(); float j = cosf(ra) * pNode->getCamera()->getZEye(); pNode->getCamera()->setEyeXYZ(i, 0, j); cocos2dx--- Node 绕Y轴旋转,布布扣,bubuko.

(转)android3D动画,绕y轴旋转

原文地址:http://blog.csdn.net/x_i_a_o_h_a_i/article/details/40449847 其实网上的3D旋转的例子很多,在这里我只是想把其代码做一个解释. 先上图: 代码: TurnAroundActivity /** * 图片浏览器的主Activity. * * @author guolin */ public class TurnAroundActivity extends Activity { /** * 根布局 */ private Relativ

实现物体绕不同轴旋转,并可以外部调用的函数

第一个文件,声明枚举类型,分别为均匀变化和加速变化 1 2 3 4 5 6 7 8 using UnityEngine; using System.Collections; public enum CTRotationType {     Uniform,     AccelerateUniformly } 第二个文件:主函数,实现围绕轴变化的两个函数,分别为均匀变化和加速变化   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

构建绕任意轴旋转的矩阵

转载请注明出处:http://www.cnblogs.com/jietian331/p/5634039.html

Unity3D 控制物体旋转详解 —— 自身绕轴旋转、缓慢旋转、鼠标控制旋转、欧拉数和四元数的关系

问题描述:昨天需要实现一个功能是根据指令左转90度或者右转90度,当时脑汁可能是有浆糊吧,居然要用直接赋值rotation,这样一来就要牵扯到eulerAngles和四元数的Euler函数了,结果忙活了好久没解决,bug层出,今天经过详细了解,解决了相关问题,一并把其他关于角度和旋转的知识点整理出来. 一.问题的解决:如何让物体绕自身轴旋转 直接上关键代码: player_cube.Rotate(-90, 0, 0); player_cube是获取的需要旋转的物体的Transform,其中-90

矩阵变换:沿任意轴旋转及其推导

http://blog.csdn.net/zsq306650083/article/details/8773996 1. 2D中绕原点旋转 设基向量p,q和r分别是朝向+x,+y和+z方向的单位向量. 旋转角度为θ,基向量p,q绕原点旋转,得到新的基向量p`和q` 即旋转矩阵R(θ)为 2. 3d中绕坐标轴旋转 01. 绕x轴旋转,基向量q和r旋转θ,得到新的基向量q`和r` 即旋转矩阵Rx(θ)为: 02. 绕y轴旋转,基向量p和r旋转θ,得到新的基向量p`和r` 即旋转矩阵Ry(θ)为: 0

直线绕z轴旋转所成曲面的方程

直线:(x-x0)/L=(y-y0)/M=(z-z0)/N绕z轴旋转所成曲面的方程为: x2+y2=α+β(z-z0)+γ(z-z0)2 其中 α=x02+y02 β=(2/N)(Lx0+My0) γ=(L2+M2)/N2 绕其他两个轴的方程类似于此. 原文地址:https://www.cnblogs.com/jmz11111/p/8157604.html

绕单轴的旋转矩阵

对于绕单轴的旋转矩阵,很多小伙伴分不清楚到底是B转W还是W转B的,下面就先用上面对旋转矩阵的理解来推导一下绕单轴的旋转矩阵,然后介绍下怎么记忆.注意对旋转正负号的定义,惯用的定义是,从原点沿着坐标轴看,顺时针为正.下面看图. 初始状态的W和B系绕Z轴旋转绕Y.X轴旋转 这样就通过计算B系各坐标轴在W系的投影得到了绕各轴旋转的  ,反之计算W系在B系的投影就可得到绕各轴旋转的  ,不过因为它们互为转置,所以得到了一个,就知道另一个了. 注意这里的W系和B系可以换成任意两个坐标系,只要把握哪个坐标系