コード例 #1
0
        public static PointPolar PtdDecartToPolar(PointD decartPointD, PointD center, PointD zeroAnglePoint)
        {
            double diffX           = zeroAnglePoint.X - center.X;
            double diffY           = zeroAnglePoint.Y - center.Y;
            double zeroAnglePointR = Math.Sqrt(diffX * diffX + diffY * diffY);
            double zeroAngle       = 0.0d;

            if (zeroAnglePointR != 0.0d)
            {
                zeroAngle = Math.Acos(diffX / zeroAnglePointR);
                if (diffY >= 0)
                {
                    zeroAngle = 2.0d * Math.PI - zeroAngle;
                }
            }

            PointPolar polarPointD = new PointPolar();

            diffX           = decartPointD.X - center.X;
            diffY           = decartPointD.Y - center.Y;
            polarPointD.R   = Math.Sqrt(diffX * diffX + diffY * diffY);
            polarPointD.Phi = Math.Acos(diffX / polarPointD.R);
            if (diffY >= 0)
            {
                polarPointD.Phi = 2.0d * Math.PI - polarPointD.Phi;
            }

            polarPointD.Phi -= zeroAngle;
            polarPointD.CropAngle(true);

            return(polarPointD);
        }
コード例 #2
0
        public static List <PointPolar> ListDecartToPolar(List <PointD> decartPointdList, PointD center, PointD zeroAnglePoint, out double zeroAngleValue)
        {
            double diffX           = zeroAnglePoint.X - center.X;
            double diffY           = zeroAnglePoint.Y - center.Y;
            double zeroAnglePointR = Math.Sqrt(diffX * diffX + diffY * diffY);
            double zeroAngle       = 0.0d;

            if (zeroAnglePointR != 0.0d)
            {
                zeroAngle = Math.Acos(diffX / zeroAnglePointR);
                if (diffY >= 0)
                {
                    zeroAngle = 2.0d * Math.PI - zeroAngle;
                }
            }

            zeroAngleValue = zeroAngle;

            List <PointPolar> retList = new List <PointPolar>();

            foreach (PointD curPointDecart in decartPointdList)
            {
                PointPolar polarPointD = new PointPolar();
                diffX           = curPointDecart.X - center.X;
                diffY           = curPointDecart.Y - center.Y;
                polarPointD.R   = Math.Sqrt(diffX * diffX + diffY * diffY);
                polarPointD.Phi = Math.Acos(diffX / polarPointD.R);
                if (diffY >= 0)
                {
                    polarPointD.Phi = 2.0d * Math.PI - polarPointD.Phi;
                }

                polarPointD.Phi -= zeroAngle;
                polarPointD.CropAngle(true);

                retList.Add(polarPointD);
            }
            return(retList);
        }