/// <summary> /// 计算反射后的功率 /// </summary> /// <param name="Pi">入射功率</param> /// <param name="ray">入射波束线段</param> /// <param name="barrier">碰撞散射体线段</param> /// <param name="dc">散射体介电常数</param> /// <returns></returns> public static double ReflectionLoss(double Pi, LineSegment ray, LineSegment barrier, double dc) { double angle = ray.Angle(barrier); double theta_i = angle > Math.PI / 2 ? angle - Math.PI / 2 : Math.PI / 2 - angle; double theta_t = Math.Asin(Math.Sin(theta_i) / Math.Sqrt(dc)); double tau = (Math.Cos(theta_i) - Math.Sqrt(dc) * Math.Cos(theta_t)) / (Math.Cos(theta_i) + Math.Sqrt(dc) * Math.Cos(theta_t)); return Pi * Math.Abs(tau); }
///// <summary> ///// 自由空间路径损耗 ///// </summary> ///// <param name="Pi"></param> ///// <param name="d"></param> ///// <param name="freq"></param> ///// <returns></returns> //public static double FreeSpacePathLoss(double Pi, double d, double freq) //{ // double dbi = 20 * Math.Log10(freq / 1e6) + 20 * Math.Log10(d / 1e3); // double ratio = Math.Pow(10, (dbi / 10)); // return Pi / ratio; //} /// <summary> /// 计算镜面反射角 /// </summary> /// <param name="ray">入射波束线段</param> /// <param name="barrier">产生碰撞的散射体线段</param> /// <param name="dir">散射体的向量旋转方向</param> /// /// <returns>出射角</returns> public static double SpecularReflection(LineSegment ray, LineSegment barrier, SCATTER_SEG_DIRECTION dir) { double result; double angle = ray.Angle(barrier); if(dir == SCATTER_SEG_DIRECTION.CLOCKWISE) { result = barrier.DirectionRadian + angle; result = result > Math.PI * 2 ? result - Math.PI * 2 : result; } else { result = barrier.DirectionRadian - angle; result = result < 0 ? result + Math.PI * 2 : result; } return result; }
/// <summary> /// 线段类的单元测试 /// </summary> /// <param name="epsilon"></param> /// <returns></returns> public static string RunTest(double epsilon=1e-3) { LineSegment This = new LineSegment(); LineSegment That = new LineSegment(); DateTime time = DateTime.Now; StringBuilder sb = new StringBuilder("LineSegment Class Test Begin at " + time.ToString("yyyy-MM-dd HH:mm:ss") + "\n"); test_log.Add(time, ""); //test Length sb.AppendLine("----------------------------"); sb.AppendLine("length test 1"); Debug.Assert(new LineSegment(new Point(0, 0), new Point(0, 0)).Length == 0, "length should be 0"); sb.AppendLine("length test 2"); Debug.Assert(new LineSegment(new Point(0, 1), new Point(1, 0)).Length == Math.Sqrt(2), "length should be sqrt(2)"); sb.AppendLine("length test 3"); Debug.Assert(new LineSegment(new Point(2, 0), new Point(0, 0)).Length == 2, "length should be 2"); sb.AppendLine("length test 4"); Debug.Assert(new LineSegment(new Point(0, 0), new Point(0, 2)).Length == 2, "length should be 2"); //test DirectionRadius sb.AppendLine("----------------------------"); sb.AppendLine("direction test 1"); Debug.Assert(new LineSegment(new Point(0, 0), new Point(0, 0)).DirectionRadian == 0, "direction should be 0"); sb.AppendLine("direction test 2"); Debug.Assert(new LineSegment(new Point(1, 0), new Point(0, 0)).DirectionRadian == 0, "direction should be 0"); sb.AppendLine("direction test 3"); Debug.Assert(new LineSegment(new Point(0, 0), new Point(0, 1)).DirectionRadian == Math.PI / 2, "direction should be pi/2"); sb.AppendLine("direction test 4"); Debug.Assert(new LineSegment(new Point(0, 0), new Point(1, 0)).DirectionRadian == Math.PI, "direction should be pi"); sb.AppendLine("direction test 5"); Debug.Assert(new LineSegment(new Point(0, 1), new Point(0, 0)).DirectionRadian == Math.PI / 2 * 3, "direction should be pi/2*3"); sb.AppendLine("direction test 6"); Debug.Assert(new LineSegment(new Point(1, 0), new Point(0, 1)).DirectionRadian == Math.PI / 4, "direction should be pi/4"); sb.AppendLine("direction test 7"); Debug.Assert(new LineSegment(new Point(0, 0), new Point(1, 1)).DirectionRadian == Math.PI / 4 * 3, "direction should be pi/4*3"); sb.AppendLine("direction test 8"); Debug.Assert(new LineSegment(new Point(0, 1), new Point(1, 0)).DirectionRadian == Math.PI / 4 * 5, "direction should be pi/4*5"); sb.AppendLine("direction test 9"); Debug.Assert(new LineSegment(new Point(1, 1), new Point(0, 0)).DirectionRadian == Math.PI / 4 * 7, "direction should be pi/4*7"); //test Angle sb.AppendLine("----------------------------"); This = new LineSegment(new Point(1, 0), new Point(0, 0)); sb.AppendLine("angle test 1"); That = new LineSegment(new Point(1, 0), new Point(0, 0)); Debug.Assert(This.Angle(That) == 0, "angle should be 0"); sb.AppendLine("angle test 2"); That = new LineSegment(new Point(0, 0), new Point(0, 1)); Debug.Assert(This.Angle(That) == Math.PI / 2, "angle should be pi/2"); sb.AppendLine("angle test 3"); That = new LineSegment(new Point(0, 0), new Point(1, 0)); Debug.Assert(This.Angle(That) == Math.PI, "angle should be pi"); sb.AppendLine("angle test 4"); That = new LineSegment(new Point(0, 1), new Point(0, 0)); Debug.Assert(This.Angle(That) == Math.PI / 2, "angle should be pi/2"); sb.AppendLine("angle test 5"); That = new LineSegment(new Point(1, 0), new Point(0, 1)); Debug.Assert(This.Angle(That) > Math.PI / 4 - epsilon && This.Angle(That) < Math.PI / 4 + epsilon, "angle should be pi/4"); sb.AppendLine("angle test 6"); Debug.Assert(new LineSegment(new Point(1, 0), new Point(0, 0)).Angle(new LineSegment(new Point(0, 0), new Point(1, 1))) == Math.PI / 4 * 3, "angle should be pi/4*3"); sb.AppendLine("angle test 7"); Debug.Assert(new LineSegment(new Point(1, 0), new Point(0, 0)).Angle(new LineSegment(new Point(0, 1), new Point(1, 0))) == Math.PI / 4 * 3, "angle should be pi/4*3"); sb.AppendLine("angle test 8"); That = new LineSegment(new Point(1, 1), new Point(0, 0)); Debug.Assert(This.Angle(That) > Math.PI / 4 - epsilon && This.Angle(That) < Math.PI / 4 + epsilon, "angle should be pi/4"); sb.AppendLine("angle test 9"); That = new LineSegment(new Point(0, 0), new Point(0, 0)); Debug.Assert(This.Angle(That) == 0, "angle should be 0"); //test JudgeIntersection sb.AppendLine("----------------------------"); This = new LineSegment(new Point(2, 2), new Point(0, 2)); sb.AppendLine("intersection test 1"); That = new LineSegment(new Point(1, 2), new Point(0, 2)); Debug.Assert(This.JudgeIntersection(That) == false, "intersection should be false"); sb.AppendLine("intersection test 2"); That = new LineSegment(new Point(1, 1), new Point(0, 1)); Debug.Assert(This.JudgeIntersection(That) == false, "intersection should be false"); sb.AppendLine("intersection test 3"); That = new LineSegment(new Point(0, 1), new Point(1, 1)); Debug.Assert(This.JudgeIntersection(That) == false, "intersection should be false"); sb.AppendLine("intersection test 4"); That = new LineSegment(new Point(1, 0), new Point(1, 1)); Debug.Assert(This.JudgeIntersection(That) == false, "intersection should be false"); sb.AppendLine("intersection test 5"); That = new LineSegment(new Point(1, 1), new Point(1, 0)); Debug.Assert(This.JudgeIntersection(That) == false, "intersection should be false"); sb.AppendLine("intersection test 6"); That = new LineSegment(new Point(1, 1), new Point(0, 2)); Debug.Assert(This.JudgeIntersection(That) == true, "intersection should be true"); sb.AppendLine("intersection test 7"); That = new LineSegment(new Point(1, 1), new Point(2, 2)); Debug.Assert(This.JudgeIntersection(That) == true, "intersection should be true"); sb.AppendLine("intersection test 8"); That = new LineSegment(new Point(3, 1), new Point(2, 2)); Debug.Assert(This.JudgeIntersection(That) == true, "intersection should be true"); sb.AppendLine("intersection test 9"); That = new LineSegment(new Point(2, 1), new Point(1, 2)); Debug.Assert(This.JudgeIntersection(That) == true, "intersection should be true"); sb.AppendLine("intersection test 10"); That = new LineSegment(new Point(1, 2), new Point(2, 3)); Debug.Assert(This.JudgeIntersection(That) == true, "intersection should be true"); sb.AppendLine("intersection test 11"); That = new LineSegment(new Point(0, 0), new Point(2, 3)); Debug.Assert(This.JudgeIntersection(That) == true, "intersection should be true"); sb.AppendLine("intersection test 12"); That = new LineSegment(new Point(1, 0), new Point(0, 3)); Debug.Assert(This.JudgeIntersection(That) == true, "intersection should be true"); sb.AppendLine("intersection test 13"); That = new LineSegment(new Point(1, 3), new Point(1, 1)); Debug.Assert(This.JudgeIntersection(That) == true, "intersection should be true"); sb.AppendLine("intersection test 14"); That = new LineSegment(new Point(3, 2), new Point(2, 2)); Debug.Assert(This.JudgeIntersection(That) == false, "intersection should be false"); sb.AppendLine("intersection test 15"); That = new LineSegment(new Point(1, 2), new Point(1, 2)); Debug.Assert(This.JudgeIntersection(That) == false, "intersection should be false"); //test GetIntersectionPoint sb.AppendLine("----------------------------"); This = new LineSegment(new Point(3, 2), new Point(1, 2)); sb.AppendLine("intersection point test 1"); That = new LineSegment(new Point(3, 1), new Point(1, 1)); Debug.Assert(This.GetIntersectionPoint(That) == null, "intersection point should be null"); sb.AppendLine("intersection point test 2"); That = new LineSegment(new Point(4, 1), new Point(3, 2)); Debug.Assert(This.GetIntersectionPoint(That) == new Point(3, 2), "intersection point should be (3, 2)"); sb.AppendLine("intersection point test 3"); That = new LineSegment(new Point(3, 1), new Point(3, 2)); Debug.Assert(This.GetIntersectionPoint(That) == new Point(3, 2), "intersection point should be (3, 2)"); sb.AppendLine("intersection point test 4"); That = new LineSegment(new Point(2, 1), new Point(3, 2)); Debug.Assert(This.GetIntersectionPoint(That) == new Point(3, 2), "intersection point should be (3, 2)"); sb.AppendLine("intersection point test 5"); That = new LineSegment(new Point(3, 2), new Point(2, 3)); Debug.Assert(This.GetIntersectionPoint(That) == new Point(3, 2), "intersection point should be (3, 2)"); sb.AppendLine("intersection point test 6"); That = new LineSegment(new Point(3, 2), new Point(4, 3)); Debug.Assert(This.GetIntersectionPoint(That) == new Point(3, 2), "intersection point should be (3, 2)"); sb.AppendLine("intersection point test 7"); That = new LineSegment(new Point(2, 1), new Point(2, 3)); Debug.Assert(This.GetIntersectionPoint(That) == new Point(2, 2), "intersection point should be (2, 2)"); sb.AppendLine("intersection point test 8"); That = new LineSegment(new Point(1, 1), new Point(3, 3)); Debug.Assert(This.GetIntersectionPoint(That) == new Point(2, 2), "intersection point should be (2, 2)"); sb.AppendLine("intersection point test 9"); That = new LineSegment(new Point(3, 3), new Point(1, 1)); Debug.Assert(This.GetIntersectionPoint(That) == new Point(2, 2), "intersection point should be (2, 2)"); sb.AppendLine("intersection point test 10"); That = new LineSegment(new Point(3, 1), new Point(1, 3)); Debug.Assert(This.GetIntersectionPoint(That) == new Point(2, 2), "intersection point should be (2, 2)"); sb.AppendLine("intersection point test 11"); That = new LineSegment(new Point(1, 3), new Point(3, 1)); Debug.Assert(This.GetIntersectionPoint(That) == new Point(2, 2), "intersection point should be (2, 2)"); sb.AppendLine("intersection point test 12"); That = new LineSegment(new Point(2, 3), new Point(0, 1)); Debug.Assert(This.GetIntersectionPoint(That) == new Point(1, 2), "intersection point should be (1, 2)"); sb.AppendLine("intersection point test 13"); That = new LineSegment(new Point(2, 2), new Point(2, 2)); Debug.Assert(This.GetIntersectionPoint(That) == null, "intersection point should be null"); test_log[time] = sb.ToString(); return test_log[time]; }