Ejemplo n.º 1
0
        //求得电场的垂直分量
        //调用方法:thisEfield.GetVerticalE(k,l)
        public Plural GetVerticalE(SpectVector k, SpectVector l)  //k为射线传播方向,l为反射中的反射面的法向量或绕射中的与棱平行的向量
        {
            SpectVector n = k.CrossMultiplied(l).GetNormalizationVector();
            Plural      p = n.DotMultiplied(this);

            return(p);
        }
Ejemplo n.º 2
0
        public SpectVector GetRightRotationVector(SpectVector vector, double rotationAngle)
        {
            double[] normalizations   = new double[4];
            double[] rotateparameters = new double[9];
            //normalizations中四个值分别为:旋转轴的单位方向向量三个分量x,y,z,和旋转角度弧度值。
            SpectVector rotationVector = vector.GetNormalizationVector();

            normalizations[0] = rotationVector.a;
            normalizations[1] = rotationVector.b;
            normalizations[2] = rotationVector.c;
            normalizations[3] = rotationAngle / 180 * Math.PI;//转换为弧度值
            //旋转矩阵
            rotateparameters[0] = Math.Cos(normalizations[3]) + normalizations[0] * normalizations[0] * (1 - Math.Cos(normalizations[3]));
            rotateparameters[1] = normalizations[0] * normalizations[1] * (1 - Math.Cos(normalizations[3])) + normalizations[2] * Math.Sin(normalizations[3]);
            rotateparameters[2] = normalizations[0] * normalizations[2] * (1 - Math.Cos(normalizations[3])) - normalizations[1] * Math.Sin(normalizations[3]);
            rotateparameters[3] = normalizations[0] * normalizations[1] * (1 - Math.Cos(normalizations[3])) - normalizations[2] * Math.Sin(normalizations[3]);
            rotateparameters[4] = Math.Cos(normalizations[3]) + normalizations[1] * normalizations[1] * (1 - Math.Cos(normalizations[3]));
            rotateparameters[5] = normalizations[1] * normalizations[2] * (1 - Math.Cos(normalizations[3])) + normalizations[0] * Math.Sin(normalizations[3]);
            rotateparameters[6] = normalizations[0] * normalizations[2] * (1 - Math.Cos(normalizations[3])) + normalizations[1] * Math.Sin(normalizations[3]);
            rotateparameters[7] = normalizations[1] * normalizations[2] * (1 - Math.Cos(normalizations[3])) - normalizations[0] * Math.Sin(normalizations[3]);
            rotateparameters[8] = Math.Cos(normalizations[3]) + normalizations[2] * normalizations[2] * (1 - Math.Cos(normalizations[3]));
            double xtemp = this.a * rotateparameters[0] + this.b * rotateparameters[3] + this.c * rotateparameters[6];
            double ytemp = this.a * rotateparameters[1] + this.b * rotateparameters[4] + this.c * rotateparameters[7];
            double ztemp = this.a * rotateparameters[2] + this.b * rotateparameters[5] + this.c * rotateparameters[8];

            return(new SpectVector(xtemp, ytemp, ztemp));
        }
Ejemplo n.º 3
0
        public RayInfo(Point one, Point two)
        {
            Origin = one;
            SpectVector temp = new SpectVector(one, two);

            RayVector = temp.GetNormalizationVector();
        }
Ejemplo n.º 4
0
        /// <summary>
        ///矢量夹角计算
        /// </summary>
        public double GetPhaseOfVector(SpectVector anotherVector)
        {
            double multipliedTemp, nTemp;

            multipliedTemp = this.DotMultiplied(anotherVector);
            double tempValue = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2) + Math.Pow(c, 2)) * Math.Sqrt(Math.Pow(anotherVector.a, 2) + Math.Pow(anotherVector.b, 2) + Math.Pow(anotherVector.c, 2));

            if (tempValue == 0)
            {
                nTemp = 0;
            }
            else
            {
                nTemp = multipliedTemp / tempValue;
            }
            if (nTemp < -1)
            {
                nTemp = -1;
            }
            if (nTemp > 1)
            {
                nTemp = 1;
            }
            double phase = Math.Acos(nTemp) / Math.PI * 180;

            return(phase);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///矢量夹角计算
        /// </summary>
        public static double VectorPhase(SpectVector k, SpectVector l)
        {
            double m, n;

            m = VectorDotMultiply(k, l);
            double temp = Math.Sqrt(Math.Pow(k.a, 2) + Math.Pow(k.b, 2) + Math.Pow(k.c, 2)) * Math.Sqrt(Math.Pow(l.a, 2) + Math.Pow(l.b, 2) + Math.Pow(l.c, 2));

            if (temp == 0)
            {
                n = 0;
            }
            else
            {
                n = m / temp;
            }
            if (n < -1)
            {
                n = -1;
            }
            if (n > 1)
            {
                n = 1;
            }
            double phase = Math.Acos(n) / Math.PI * 180;

            return(phase);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///矢量点乘
        /// </summary>
        public double DotMultiplied(SpectVector anotherVector)
        //调用方法:thisVector.DotMultiplied(anotherVector)
        {
            double multipled = a * anotherVector.a + b * anotherVector.b + c * anotherVector.c;

            return(multipled);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///求射线打到一个平面后得到的反射射线
        /// </summary>
        /// <param name="reflectionFace">反射面</param>
        /// <returns>反射射线</returns>
        public RayInfo GetReflectionRay(Face reflectionFace, Point crossPoint)
        {
            Point       mirrorPoint = this.Origin.GetMirrorPoint(reflectionFace);
            SpectVector vector      = new SpectVector(mirrorPoint, crossPoint);

            return(new RayInfo(crossPoint, vector));
        }
Ejemplo n.º 8
0
        /// <summary>
        ///获得直线与平面的交点
        /// </summary>
        /// <param viewFace="p">平面</param>
        /// <returns>直线与三角面的交点</returns>
        public Point GetCrossPointBetweenStraightLineAndFace(Face viewFace)
        {
            SpectVector vector = viewFace.NormalVector.GetNormalizationVector();//归一化
            double      temp   = this.RayVector.DotMultiplied(vector);

            if (Math.Abs(temp) < 0.00001)//如果向量和平面平行则返回null
            {
                return(null);
            }
            else
            {
                double TriD      = vector.a * viewFace.Vertices[0].X + vector.b * viewFace.Vertices[0].Y + vector.c * viewFace.Vertices[0].Z;
                double temp1     = vector.a * this.Origin.X + vector.b * this.Origin.Y + vector.c * this.Origin.Z - TriD;
                double t         = -temp1 / temp;
                Point  tempPoint = new Point(this.RayVector.a * t + this.Origin.X, this.RayVector.b * t + this.Origin.Y, this.RayVector.c * t + this.Origin.Z);
                if (viewFace.JudgeIfPointInFace(tempPoint))
                {
                    return(tempPoint);
                }
                else
                {
                    return(null);//如果求出的交点不在三角面内,则返回空
                }
            }
        }
Ejemplo n.º 9
0
 public ClassNewRay(Point point, SpectVector sv, bool fg, List <Path> path = null)
 {
     this.Origin  = point;
     this.SVector = sv;
     this.Flag    = fg;
     this.Path    = path;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 当点在直线上得到无限长棱上的绕射点
        /// </summary>
        /// <param name="origin">起始点</param>
        /// <param name="target">观测点</param>
        /// <returns>绕射点</returns>
        public Point GetInfiniteDiffractionPointWhenInLine(Point origin, Point target)
        {
            double h1     = this.getDistanceP2Line(origin);
            double h2     = this.getDistanceP2Line(target);
            Point  pedal1 = this.GetPedalPoint(origin);
            Point  pedal2 = this.GetPedalPoint(target);

            if (h1 == 0)
            {
                return(origin);
            }
            if (h2 == 0)
            {
                return(target);
            }
            if (Math.Abs(pedal1.X - pedal2.X) < 0.000001 && Math.Abs(pedal1.Y - pedal2.Y) < 0.000001 && Math.Abs(pedal1.Z - pedal2.Z) < 0.000001)
            {
                return(pedal1);
            }
            double      ratio         = h1 / (h1 + h2);;
            SpectVector tempVector    = new SpectVector(pedal1, pedal2);
            Point       diffractPoint = new Point(tempVector.a * ratio + pedal1.X, tempVector.b * ratio + pedal1.Y, tempVector.c * ratio + pedal1.Z);

            return(diffractPoint);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 判断点是否在三角面中
 /// </summary>
 /// <param name="viewPoint">点</param>
 /// <returns>返回点是否在三角面内的布尔值</returns>
 public override bool JudgeIfPointInFace(Point viewPoint)
 {
     if (viewPoint.equal(this.vertices[0]) || viewPoint.equal(this.vertices[1]) || viewPoint.equal(this.vertices[2]))
     {
         return(true);
     }
     else
     {
         SpectVector Vda    = new SpectVector(viewPoint, this.vertices[0]);
         SpectVector Vdb    = new SpectVector(viewPoint, this.vertices[1]);
         SpectVector Vdc    = new SpectVector(viewPoint, this.vertices[2]);
         double      Sdab   = 0.5 * Vda.Mag() * Vdb.Mag() * Math.Sin(Vda.GetPhaseOfVector(Vdb) * Math.PI / 180); //三角形ABD的面积
         double      Sdac   = 0.5 * Vda.Mag() * Vdc.Mag() * Math.Sin(Vda.GetPhaseOfVector(Vdc) * Math.PI / 180); //三角形ACD的面积
         double      Sdbc   = 0.5 * Vdb.Mag() * Vdc.Mag() * Math.Sin(Vdb.GetPhaseOfVector(Vdc) * Math.PI / 180); //三角行BCD的面积
         double      Sabc   = GetTriangleArea();                                                                 //三角面ABC的面积
         double      Dvalue = Sabc - Sdab - Sdac - Sdbc;                                                         //若点在三角面内,则Sabc+Sabc+Sacd=Sbcd;
         if (Math.Abs(Dvalue) < 0.000001)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        ///求两个向量的中间向量
        /// </summary>
        public SpectVector GetMiddleVectorOfTwoVectors(SpectVector otherVector)
        {
            SpectVector unitVector1 = this.GetNormalizationVector();
            SpectVector unitVector2 = otherVector.GetNormalizationVector();

            return(new SpectVector((unitVector1.a + unitVector2.a) / 2, (unitVector1.b + unitVector2.b) / 2, (unitVector1.c + unitVector2.c) / 2));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 判断一点是否在线段内
        /// </summary>
        /// <param name="viewPoint">点</param>
        /// <returns>返回点是否在线段内的布尔值</returns>
        public bool JudgeIfPointInLineRange(Point viewPoint)
        {
            //         if (this.SwitchToRay().JudgeIfPointIsInStraightLine(viewPoint))//点在线段所在直线上
            //         {
            //             if (((viewPoint.X >= this.startPoint.X && viewPoint.X <= this.endPoint.X) || (viewPoint.X <= this.startPoint.X && viewPoint.X >= this.endPoint.X)) &&
            //                 ((viewPoint.Y >= this.startPoint.Y && viewPoint.Y <= this.endPoint.Y) || (viewPoint.Y <= this.startPoint.Y && viewPoint.Y >= this.endPoint.Y)) &&
            //                 ((viewPoint.Z >= this.startPoint.Z && viewPoint.Z <= this.endPoint.Z) || (viewPoint.Z <= this.startPoint.Z && viewPoint.Z >= this.endPoint.Z)))
            //             { return true; }
            //         }
            //          return false;

            if (viewPoint.equal(this.startPoint) || viewPoint.equal(this.endPoint))
            {
                return(true);
            }
            SpectVector vectorFromStartPointToViewPoint = new SpectVector(this.startPoint, viewPoint);
            SpectVector vectorFromViewPointToEndPoint   = new SpectVector(viewPoint, this.endPoint);
            SpectVector vectorFromEndPointToViewPoint   = new SpectVector(this.endPoint, viewPoint);
            SpectVector vectorFromViewPointToStartPoint = new SpectVector(viewPoint, this.startPoint);

            if (vectorFromStartPointToViewPoint.IsParallelAndSamedirection(vectorFromViewPointToEndPoint) &&
                vectorFromEndPointToViewPoint.IsParallelAndSamedirection(vectorFromViewPointToStartPoint))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 获取三角面的面积
        /// </summary>
        public double GetTriangleArea()
        {
            SpectVector Vab = new SpectVector(this.vertices[0], this.vertices[1]);
            SpectVector Vac = new SpectVector(this.vertices[0], this.vertices[2]);

            return(0.5 * Vab.Mag() * Vac.Mag() * Math.Sin(Vab.GetPhaseOfVector(Vac) * Math.PI / 180));//三角面ABC的面积
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 求射线与四边形的交点
        /// </summary>
        /// <param oneRay="viewPoint">射线</param>
        /// <returns>返回射线与四边形的交点,若无交点则返回null</returns>
        public Point GetCrossPointWithRay(RayInfo oneRay)
        {
            SpectVector unitVector = this.normalVector.GetNormalizationVector();//归一化
            double      temp       = oneRay.RayVector.DotMultiplied(unitVector);

            if (Math.Abs(temp) < 0.00001)//如果向量和平面平行则返回null
            {
                return(null);
            }
            else
            {
                double TriD      = unitVector.a * this.vertices[0].X + unitVector.b * this.vertices[0].Y + unitVector.c * this.vertices[0].Z;
                double temp1     = unitVector.a * oneRay.Origin.X + unitVector.b * oneRay.Origin.Y + unitVector.c * oneRay.Origin.Z - TriD;
                double t         = -temp1 / temp;
                Point  tempPoint = new Point(oneRay.RayVector.a * t + oneRay.Origin.X, oneRay.RayVector.b * t + oneRay.Origin.Y, oneRay.RayVector.c * t + oneRay.Origin.Z);
                if (!oneRay.RayVector.IsParallelAndSamedirection(new SpectVector(oneRay.Origin, tempPoint)))
                {
                    return(null);
                }
                if (this.JudgeIfPointInFace(tempPoint))
                {
                    return(tempPoint);
                }
                else
                {
                    return(null);//如果求出的交点不在三角面内,则返回空
                }
            }
        }
Ejemplo n.º 16
0
        //求得电场的垂直分量
        public static Plural GetVerticalE(EField e, SpectVector k, SpectVector l)  //k为射线传播方向,l为反射中的反射面的法向量或绕射中的与棱平行的向量
        {
            SpectVector n = SpectVector.VectorCrossMultiply(k, l);
            Plural      p = SpectVector.VectorDotMultiply(e, n);

            return(p);
        }
Ejemplo n.º 17
0
        /// <summary>
        ///获得平面的法向量
        /// </summary>
        public SpectVector GetNormalVector()
        {
            SpectVector vector12 = new SpectVector(this.vertices[0], this.vertices[1]);
            SpectVector vector13 = new SpectVector(this.vertices[0], this.vertices[2]);

            return(vector12.CrossMultiplied(vector13));
        }
Ejemplo n.º 18
0
        /// <summary>
        ///复数向量与矢量的点乘运算
        /// </summary>
        public static Plural VectorDotMultiply(EField e, SpectVector l)
        {
            Plural p = new Plural();

            p.Re = e.X.Re * l.a + e.Y.Re * l.b + e.Z.Re * l.c;
            p.Im = e.X.Im * l.a + e.Y.Im * l.b + e.Z.Im * l.c;
            return(p);
        }
Ejemplo n.º 19
0
 public SpaceFace(Point facePoint, SpectVector normalVector, FaceType faceStyle, FaceID faceID, Material material, int materialNumber)
     : this(facePoint, normalVector)
 {
     this.faceStyle      = faceStyle;
     this.faceID         = faceID;
     this.material       = material;
     this.materialNumber = materialNumber;
 }
Ejemplo n.º 20
0
        //求得电场的水平分量
        public static Plural GetHorizonalE(EField e, SpectVector k, SpectVector l)
        {
            SpectVector n = SpectVector.VectorCrossMultiply(k, l);   //入射面的法向量
            SpectVector m = SpectVector.VectorCrossMultiply(k, n);
            Plural      p = SpectVector.VectorDotMultiply(e, m);

            return(p);
        }
Ejemplo n.º 21
0
        /// <summary>
        ///求异面直线公垂线在该直线上的垂足
        /// </summary>
        public Point GetFootPointWithSkewLine(RayInfo otherRay)
        {
            SpectVector verticalVector = this.RayVector.CrossMultiplied(otherRay.RayVector);//求两条异面直线的公垂线的向量
            Face        viewFace       = new SpaceFace(this.Origin, this.RayVector.CrossMultiplied(verticalVector));
            Point       crossPoint     = otherRay.GetCrossPointBetweenStraightLineAndFace(viewFace);

            return(this.getDropFoot(crossPoint));
        }
Ejemplo n.º 22
0
        //求得电场的水平分量
        //调用方法:thisEfield.GetVerticalE(k,l)
        public Plural GetHorizonalE(SpectVector k, SpectVector l)
        {
            SpectVector n = k.CrossMultiplied(l);   //入射面的法向量
            SpectVector m = k.CrossMultiplied(n).GetNormalizationVector();
            Plural      p = m.DotMultiplied(this);

            return(p);
        }
Ejemplo n.º 23
0
        /// <summary>
        ///复数与矢量的点乘运算
        /// </summary>
        public static EField VectorDotMultiply(Plural p, SpectVector l)
        {
            Plural X = new Plural(l.a * p.Re, l.a * p.Im);
            Plural Y = new Plural(l.b * p.Re, l.b * p.Im);
            Plural Z = new Plural(l.c * p.Re, l.c * p.Im);
            EField e = new EField(X, Y, Z);

            return(e);
        }
Ejemplo n.º 24
0
        /// <summary>
        ///求平面面方程Ax+By+Cz+D=0的四个系数A,B,C,D
        /// </summary>
        public double[] GetFaceEquationFactor()
        {
            double[]    para       = new double[4];
            SpectVector unitVector = this.normalVector.GetNormalizationVector();

            para[0] = unitVector.a;
            para[1] = unitVector.b;
            para[2] = unitVector.c;
            para[3] = -(unitVector.a * this.vertices[0].X + unitVector.b * this.vertices[0].Y + unitVector.c * this.vertices[0].Z);
            return(para);
        }
Ejemplo n.º 25
0
        /// <summary>
        ///判断两个向量在XY平面的投影是否平行且同向
        /// </summary>
        public bool IsParallelAndSamedirectionInXYPlane(SpectVector linevector)
        {
            double temp = (linevector.a * a + linevector.b * b) / (GetMagInXY() * linevector.GetMagInXY());

            if (Math.Abs(temp - 1) <= 0.00000001)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        ///判断两个向量是否平行
        /// </summary>
        public bool IsParallel(SpectVector linevector)
        {
            double temp = (linevector.a * a + linevector.b * b + linevector.c * c) / (Mag() * linevector.Mag());

            if (Math.Abs(temp - 1) <= 0.00000001 || Math.Abs(temp + 1) <= 0.00000001)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        ///判断两个向量是否垂直
        /// </summary>
        public bool IsVertical(SpectVector linevector)
        {
            double temp = linevector.a * a + linevector.b * b + linevector.c * c;

            if (Math.Abs(temp) <= 0.00000001)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        ///求直线与平面的夹角
        /// </summary>
        /// <param line="face">平面</param>
        /// <returns>直线与平面的夹角</returns>
        public double GetAngleWithFace(Face face)
        {
            SpectVector normalVector = face.GetNormalVector();                        //获得平面的法向量
            double      crossAngle   = this.RayVector.GetPhaseOfVector(normalVector); //获得射线与法向量的夹角

            if ((crossAngle <= 90) && (0 < crossAngle))
            {
                return(90 - crossAngle);
            }
            else
            {
                return(crossAngle - 90);
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        ///求射线打到一个平面后得到的反射射线
        /// </summary>
        /// <param name="reflectionFace">反射面</param>
        /// <returns>反射射线</returns>
        public RayInfo GetReflectionRay(Face reflectionFace)
        {
            Point crossPoint = this.GetCrossPointBetweenStraightLineAndFace(reflectionFace);

            if (crossPoint == null)
            {
                return(null);
            }
            else
            {
                Point       mirrorPoint = this.Origin.GetMirrorPoint(reflectionFace);
                SpectVector vector      = new SpectVector(mirrorPoint, crossPoint);
                return(new RayInfo(crossPoint, vector));
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        ///求两条异面直线的距离
        /// </summary>
        public double GetDistanceOfNonUniplanarRays(RayInfo otherRay)
        {
            if (this.Origin.equal(otherRay.Origin) || this.RayVector.IsParallel(otherRay.RayVector))//两射线共起点或平行时用此方法无法计算,且不符合条件
            {
                return(0);
            }
            SpectVector verticalLine = SpectVector.VectorCrossMultiply(this.RayVector, otherRay.RayVector);
            double      thi          = verticalLine.GetPhaseOfVector(new SpectVector(this.Origin, otherRay.Origin));

            if (thi > 90)
            {
                thi = 180 - thi;
            }
            return(this.Origin.GetDistance(otherRay.Origin) * Math.Cos(thi * Math.PI / 180));
        }