ProjectorPInfo.cs 3.0 KB
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TSA_V.DeviceLibrary
{
   public  class ProjectorPInfo
    {
        public ProjectorPInfo(double x, double y, int type=1,int polaritiesType=0, int angle=0,int sizeX=4, int sizeY=4,int lineWidth=2,string showText="",int color=-1)
        {
            this.PX = x;
            this.PY = y;
            this.PType = type;
            this.SizeX = sizeX;
            this.SizeY = sizeY;
            this.PenWidth = lineWidth;
            this.ShowText = showText;
            this.showColor = color;
            this.PolaritiesType= polaritiesType;
            this.PolarityAngle = angle;
        }
        public double PX = 2;
        public double PY = 2;
        public int PType = 1;

        public int SizeX = 4;
        public int SizeY = 4;
        /// <summary>
        /// 线条宽度
        /// </summary>
        public int PenWidth = 2;

        public string ShowText = "";

        public int showColor = -1;

        /// <summary>
        /// 极性,
        /// </summary>
        public int PolaritiesType = 0;


        /// <summary>
        /// 极性角度,
        /// </summary>
        public int PolarityAngle { get; set; } = 0;

        public static int getAngleByType(int type, int angle)
        {
            int ret = 0;
            switch (type)
            {
                case 0:
                    break;
                case 1:
                    ret = 270;
                    break;
                case 2:
                    ret = 90;
                    break;
                case 3:
                    ret = 180;
                    break;
                case 4:
                    ret = 0;
                    break;
                case 5:
                    ret = 225;
                    break;
                case 6:
                    ret = 315;
                    break;
                case 7:
                    ret = 135;
                    break;
                case 8:
                    ret = 45;
                    break;

                case 9:
                    ret = angle;
                    break;
            }
            return ret;
        }

        /// <summary>
        /// 计算极性的中心位置
        /// </summary>
        /// <param name="point">点位中心</param>
        /// <param name="distance">距离</param>
        /// <param name="angleInDegrees">角度</param>
        /// <returns></returns>
        public static  Point CalculatePoint(Point point, double distance, double angleInDegrees)
        {
            double angleInRadians = angleInDegrees * (Math.PI / 180.0);
            double deltaX = distance * Math.Cos(angleInRadians);
            double deltaY = distance * Math.Sin(angleInRadians);

            int newX = (int)(point.X + deltaX);
            int newY = (int)(point.Y + deltaY);

            return new Point(newX, newY);
        }
    }
}