7 #include "cetlib_except/exception.h" 23 const double intercept[],
24 const double slopes[],
65 if (!(xyz[0] >= xlo && xyz[0] <= xhi) || !(xyz[1] >= ylo && xyz[1] <= yhi) ||
66 !(xyz[2] >= zlo && xyz[2] <= zhi))
68 <<
" in the specififed box\n";
74 if (dxyz[0] > 0.0) { dx = (xhi - xyz[0]) / dxyz[0]; }
75 else if (dxyz[0] < 0.0) {
76 dx = (xlo - xyz[0]) / dxyz[0];
78 if (dxyz[1] > 0.0) { dy = (yhi - xyz[1]) / dxyz[1]; }
79 else if (dxyz[1] < 0.0) {
80 dy = (ylo - xyz[1]) / dxyz[1];
82 if (dxyz[2] > 0.0) { dz = (zhi - xyz[2]) / dxyz[2]; }
83 else if (dxyz[2] < 0.0) {
84 dz = (zlo - xyz[2]) / dxyz[2];
89 if (dx < dy && dx < dz)
91 else if (dy < dz && dy < dx)
93 else if (dz < dx && dz < dy)
97 for (
int i = 0; i < 3; ++i) {
98 xyzout[i] = xyz[i] + dxyz[i] *
d;
113 const double intercept[],
114 const double slopes[],
117 double s = (slopes[0] * (point[0] - intercept[0]) + slopes[1] * (point[1] - intercept[1]) +
118 slopes[2] * (point[2] - intercept[2]));
119 double sd = (slopes[0] * slopes[0] + slopes[1] * slopes[1] + slopes[2] * slopes[2]);
122 closest[0] = intercept[0] + s * slopes[0];
123 closest[1] = intercept[1] + s * slopes[1];
124 closest[2] = intercept[2] + s * slopes[2];
131 closest[0] = intercept[0];
132 closest[1] = intercept[1];
133 closest[2] = intercept[2];
135 return std::sqrt(pow((point[0] - closest[0]), 2) + pow((point[1] - closest[1]), 2) +
136 pow((point[2] - closest[2]), 2));
171 double lo[3] = {x_lo, y_lo, z_lo};
172 double hi[3] = {x_hi, y_hi, z_hi};
175 double facecoord[6] = {lo[0], hi[0], lo[1], hi[1], lo[2], hi[2]};
177 int intersect[6] = {0, 0, 0, 0, 0, 0};
180 for (
int i = 0; i < 3; i++) {
182 for (
int p = 0; p < 2; p++) {
184 point[i] = facecoord[count];
185 distance[i] = point[i] - x0[i];
187 double C_dg = distance[i] / gradient[i];
189 for (
int m = 0; m < 3; m++) {
190 distance[m] = C_dg * gradient[m];
192 for (
int n = 0;
n < 3;
n++) {
193 point[
n] = x0[
n] + distance[
n];
210 default:
throw std::logic_error(
"Big trouble");
214 if (lo[j] < point[j] && point[j] < hi[j] && lo[k] < point[k] && point[k] < hi[k]) {
221 int direction = distance[i] * gradient[i] /
222 std::sqrt((distance[i] * distance[i]) * (gradient[i] * gradient[i]));
223 bool directed = (direction + 1) / 2;
229 int normal = pow(-1, count + 1);
230 int thru = normal * gradient[i] / std::sqrt(gradient[i] * gradient[i]);
231 intersect[count] = thru;
241 for (
int face = 0; face < 6; ++face) {
242 passes += (intersect[face] * intersect[face]);
245 if (passes == 0) {
return 0; }
bool CrossesBoundary(double x0[], double gradient[], double x_lo, double x_hi, double y_lo, double y_hi, double z_lo, double z_hi, double point[])
double ClosestApproach(const double point[], const double intercept[], const double slopes[], double closest[])
void ProjectToBoxEdge(const double xyz[], const double dxyz[], double xlo, double xhi, double ylo, double yhi, double zlo, double zhi, double xyzout[])
Namespace collecting geometry-related classes utilities.
cet::coded_exception< error, detail::translate > exception