int recursionsStopper; //safety variable to avoid endless recursions. /// <summary> /// If the new location is on another face than the initial one, this method will loop until the final location of the itteretation is found. /// </summary> /// <param name="holes"></param> /// <param name="p"></param> /// <param name="parameter"></param> /// <param name="velocity"></param> /// <param name="faceIndex"></param> private void NewLocationCheck(IList<Hole> holes, Point3d p, double parameter, Vector3d velocity, int faceIndex) { recursionsStopper += 1; bool intersection; int edgeParameter; int vertexOneIndex; int vertexTwoIndex; double moveParameter; velocity = parameter * velocity; HasMovedOutsideFace(p, velocity, faceIndex, out intersection, out edgeParameter, out moveParameter); if (intersection) { GetVertexIndexesOfEdge(faceIndex, edgeParameter, out vertexOneIndex, out vertexTwoIndex); if (IsEdgeNaked(vertexOneIndex, vertexTwoIndex, faceIndex)) { this.newPoint = BounceOfBoundary(p, velocity, vertices[vertexOneIndex], vertices[vertexTwoIndex], mesh.FaceNormals[faceIndex]); this.meshFullPoint = mesh.ClosestMeshPoint(this.newPoint, 0.0); } else { Point3d intersectionPoint = p + velocity * moveParameter * 1.01; //multiplied by 1.01 to make sure that it doesn't cross same edge twice Vector3d RotatedVelocityVector = RotateVectorToNewFace(mesh.FaceNormals[faceIndex], mesh.FaceNormals[getOtherFaceIndex(vertexOneIndex, vertexTwoIndex, faceIndex)], vertices[vertexOneIndex], vertices[vertexTwoIndex], velocity); this.newPoint = intersectionPoint + RotatedVelocityVector * (1 - moveParameter); this.meshFullPoint = mesh.ClosestMeshPoint(newPoint, 0.0); this.newVelocityVector = RotatedVelocityVector; if (recursionsStopper < 30) { this.NewLocationCheck(holes, intersectionPoint, (1 - moveParameter), newVelocityVector, getOtherFaceIndex(vertexOneIndex, vertexTwoIndex, faceIndex)); } } } }
/// <summary> /// Calculates the new location of a point after being moved. /// </summary> /// <param name="holes"></param> public void CalculateNewLocation(IList<Hole> holes) { this.CalculateNewRadius(); this.CalculateVelocity(holes); this.newPoint = this.point + this.newVelocityVector; this.meshFullPoint = mesh.ClosestMeshPoint(newPoint, 0.0); this.NewLocationCheck(holes, this.point, 1, this.newVelocityVector, mesh.FaceIndexOfClosestPoint(this.point)); }