/// <summary> /// 更新绕射棱范围 /// </summary> /// <param name="triangle">绕射棱前一三角面</param> /// <param name="diffractEdge">要更新的绕射棱</param> /// <param name="point">接收点(与三角面共同确定棱的范围)</param> /// <returns>更新后的绕射棱</returns> private AdjacentEdge GetNewDiffractEdge(Triangle triangle, AdjacentEdge diffractEdge, Point point) { AdjacentEdge newDiffractEdge = new AdjacentEdge(); Point point1 = diffractEdge.GetDiffractionPoint(triangle.Vertices[0], point); Point point2 = diffractEdge.GetDiffractionPoint(triangle.Vertices[1], point); Point point3 = diffractEdge.GetDiffractionPoint(triangle.Vertices[2], point); double distance12 = point1.GetDistance(point2); double distance13 = point1.GetDistance(point3); double distance23 = point2.GetDistance(point3); if (distance12 >= distance13 && distance12 >= distance23) { newDiffractEdge.StartPoint = point1; newDiffractEdge.EndPoint = point2; } else if (distance13 >= distance12 && distance13 >= distance23) { newDiffractEdge.StartPoint = point1; newDiffractEdge.EndPoint = point3; } else { newDiffractEdge.StartPoint = point2; newDiffractEdge.EndPoint = point3; } return(newDiffractEdge); }
public void GetDiffractionPointTest7() { AdjacentEdge target = new AdjacentEdge(new Point(0, 0, 1), new Point(0, 0, -1)); // TODO: 初始化为适当的值 Point origin = new Point(-1, 0, 0); // TODO: 初始化为适当的值 Point target1 = new Point(1, 0, 3); // TODO: 初始化为适当的值 Point actual; actual = target.GetDiffractionPoint(origin, target1); Assert.IsTrue(actual == null); }
public void GetDiffractionPointTest2() { AdjacentEdge target = new AdjacentEdge(new Point(0, 0, 1), new Point(0, 0, -1)); // TODO: 初始化为适当的值 Point origin = new Point(-1, 0, 0); // TODO: 初始化为适当的值 Point target1 = new Point(-1, 1, 0); // TODO: 初始化为适当的值 Point expected = new Point(0, 0, 0); // TODO: 初始化为适当的值 Point actual; actual = target.GetDiffractionPoint(origin, target1); Assert.IsTrue(Math.Abs(expected.X - actual.X) < 0.000001 && Math.Abs(expected.Y - actual.Y) < 0.000001 && Math.Abs(expected.Z - actual.Z) < 0.000001); }
/// <summary> /// 计算两次绕射的绕射点 /// </summary> /// <param name="edge1">第一条绕射棱</param> /// <param name="edge2">第二条绕射棱</param> /// <param name="beginPoint">第一条绕射棱前的点</param> /// <param name="endPoint">第二条绕射棱后的点</param> /// <returns>用List的形式返回两个点的坐标</returns> private List <Point> GetTwoDiffractionPoints(AdjacentEdge edge1, AdjacentEdge edge2, Point beginPoint, Point endPoint) { Point p1 = edge1.GetDiffractionPoint(beginPoint, edge2.StartPoint); Point p2 = edge1.GetDiffractionPoint(beginPoint, edge2.EndPoint); Point p21 = edge2.StartPoint; Point p22 = edge2.EndPoint; AdjacentEdge tempLine = new AdjacentEdge(new Point(-10000 * edge2.LineVector.a + endPoint.X, -10000 * edge2.LineVector.b + endPoint.Y, -10000 * edge2.LineVector.c + endPoint.Z), new Point(10000 * edge2.LineVector.a + endPoint.X, 10000 * edge2.LineVector.b + endPoint.Y, 10000 * edge2.LineVector.c + endPoint.Z), edge2.LineVector); double angle1 = SpectVector.VectorPhase(new SpectVector(p1, edge2.StartPoint), edge2.LineVector); double angle2 = SpectVector.VectorPhase(new SpectVector(p2, edge2.EndPoint), edge2.LineVector); SpectVector sp1 = edge2.getVectorFromEdge2EdgeWithAngle(p1, angle1, tempLine).RayVector; SpectVector sp2 = edge2.getVectorFromEdge2EdgeWithAngle(p2, angle2, tempLine).RayVector; RayInfo ray1 = new RayInfo(p1, sp1); RayInfo ray2 = new RayInfo(p2, sp2); Point dropFoot1 = ray1.getDropFoot(endPoint); Point dropFoot2 = ray2.getDropFoot(endPoint); double distance1 = endPoint.GetDistance(dropFoot1); double distance2 = endPoint.GetDistance(dropFoot2); List <Point> diffractPoints = new List <Point>(); int i = 20; while (i-- > 0) { if (distance1 < 0.00001) { diffractPoints.Add(p1); diffractPoints.Add(p21); break; } if (distance2 < 0.00001) { diffractPoints.Add(p2); diffractPoints.Add(p22); break; } Point tempPoint = new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2, (p1.Z + p2.Z) / 2); double tempAngle1 = SpectVector.VectorPhase(new SpectVector(beginPoint, tempPoint), edge1.LineVector); RayInfo tempRay1 = edge1.getVectorFromEdge2EdgeWithAngle(tempPoint, tempAngle1, edge2); double tempAngle2 = SpectVector.VectorPhase(tempRay1.RayVector, edge2.LineVector); RayInfo tempRay2 = edge2.getVectorFromEdge2EdgeWithAngle(tempRay1.Origin, tempAngle2, tempLine); Point tempDropFoot = new RayInfo(tempRay1.Origin, tempRay2.RayVector).getDropFoot(endPoint); double tempDistance = tempDropFoot.GetDistance(endPoint); SpectVector tempSP1 = new SpectVector(dropFoot1, edge2.StartPoint); SpectVector tempSP2 = new SpectVector(dropFoot2, edge2.StartPoint); SpectVector tempSP3 = new SpectVector(tempDropFoot, edge2.StartPoint); SpectVector tempSP4 = new SpectVector(endPoint, edge2.StartPoint); double endAngle12 = SpectVector.VectorPhase(tempSP1, tempSP2); double endAngle13 = SpectVector.VectorPhase(tempSP1, tempSP3); double endAngle23 = SpectVector.VectorPhase(tempSP2, tempSP3); double endAngle14 = SpectVector.VectorPhase(tempSP1, tempSP4); if (endAngle14 > endAngle13) { p1 = tempPoint; angle1 = tempAngle2; p21 = tempRay1.Origin; dropFoot1 = tempDropFoot; distance1 = tempDistance; } else if (endAngle14 < endAngle13) { p2 = tempPoint; angle2 = tempAngle2; p22 = tempRay1.Origin; dropFoot2 = tempDropFoot; distance2 = tempDistance; } else { if (distance1 < 0.1) { diffractPoints.Add(p1); diffractPoints.Add(p21); break; } if (distance2 < 0.1) { diffractPoints.Add(p2); diffractPoints.Add(p22); break; } throw new Exception("二次绕射反向问题"); } } return(diffractPoints); }