23 #include "math_util.h"
31 : x0(a), x1(b), radius(in_radius), _tag_id(
id)
44 return (a - b).
norm();
47 nec_float length()
const
49 return distance(x0, x1);
65 nec_float epsa = b.radius / length();
66 nec_float epsb = radius / b.length();
68 std::vector<nec_wire> ret;
70 if (d2 > (radius + b.radius))
return ret;
72 if ((sa >= -epsa) && (sa <= 1.0 + epsa) && (sb >= -epsb) && (sb <= 1.0 + epsb))
77 if (sa > epsa) ret.push_back(
nec_wire(x0, a_pt, radius,_tag_id));
78 if (sa < 1.0 - epsa) ret.push_back(
nec_wire(a_pt, x1, radius,_tag_id));
80 if (sb > epsb) ret.push_back(
nec_wire(b.x0, b_pt, b.radius,b._tag_id));
81 if (sb < 1.0 - epsb) ret.push_back(
nec_wire(b_pt, b.x1, b.radius, b._tag_id));
93 nec_float a0x = x0.x(); nec_float a0y = x0.y(); nec_float a0z = x0.z();
94 nec_float a1x = x1.x(); nec_float a1y = x1.y(); nec_float a1z = x1.z();
96 nec_float b0x = b0.x(); nec_float b0y = b0.y(); nec_float b0z = b0.z();
150 nec_float sa = (a1x*b0x + a1y*b0y + a1z*b0z - a0x*a1x - a0x*b0x - a0y*a1y - a0y*b0y - a0z*a1z - a0z*b0z + a0x*a0x + a0y*a0y + a0z*a0z)/
151 (-2.0*a0x*a1x - 2*a0y*a1y - 2.0*a0z*a1z + a0x*a0x + a0y*a0y + a0z*a0z + a1x*a1x + a1y*a1y + a1z*a1z);
152 if (sa < 0) sa = 0.0;
153 if (sa > 1.0) sa = 1.0;
157 if (distance(a_pt, b0) > radius)
return false;
165 nec_float d1 = distance(x0, b.x0);
166 nec_float d2 = distance(x0, b.x1);
167 nec_float da = std::min(d1,d2);
169 nec_float d3 = distance(x1, b.x1);
170 nec_float d4 = distance(x1, b.x0);
171 nec_float db = std::min(d3,d4);
173 if ((std::abs(da) < radius) && (std::abs(db) < radius))
217 nec_float& distance, nec_float& sa, nec_float& sb)
219 nec_float a0x = a0.x(); nec_float a0y = a0.y(); nec_float a0z = a0.z();
220 nec_float b0x = b0.x(); nec_float b0y = b0.y(); nec_float b0z = b0.z();
221 nec_float a1x = a1.x(); nec_float a1y = a1.y(); nec_float a1z = a1.z();
222 nec_float b1x = b1.x(); nec_float b1y = b1.y(); nec_float b1z = b1.z();
224 nec_float a01x = (a0x - a1x);
225 nec_float a01y = (a0y - a1y);
226 nec_float a01z = (a0z - a1z);
228 nec_float b01x = (b0x - b1x);
229 nec_float b01y = (b0y - b1y);
230 nec_float b01z = (b0z - b1z);
232 nec_float moda = (a01x*a01x + a01y*a01y + a01z*a01z);
233 nec_float modb = (b01x*b01x + b01y*b01y + b01z*b01z);
235 nec_float tmp2 = (a01x*b01x + a01y*b01y + a01z*b01z);
237 nec_float den = (-4.0*tmp2*tmp2 + 4.0*moda*modb);
239 distance = 9.0e9; sa = 2.0; sb = 2.0;
240 if (0 == den)
return;
242 nec_float tmp3 = (-4.0*(a0x*a0x + a0y*a0y + a1x*b0x - a0x*(a1x + b0x) + a1y*b0y - a0y*(a1y + b0y) + a01z*(a0z - b0z))*tmp2 + 4.0*moda*((a0x - b0x)*b01x + (a0y - b0y)*b01y + (a0z - b0z)*b01z));
244 sa = (a0x*a01x + a0y*a01y + a0z*a01z - a01x*b0x - a01y*b0y - a01z*b0z - tmp3*tmp2/den)/moda;
248 nec_float d2 = pow((a0x - b0x + sa*(a1x - a0x) - sb*(b1x - b0x)),2) +
249 pow((a0z - b0z + sa*(a1z - a0z) - sb*(b1z - b0z)),2) +
250 pow((a0y - b0y + sa*(a1y - a0y) - sb*(b1y - b0y)),2);
252 distance = std::sqrt(d2);
A class to handle properties of wires.
Definition: nec_wire.h:27
bool intersect(nec_3vector &b0)
Calculate whether the point is inside the wire.
Definition: nec_wire.h:91
A Class for handling 3 dimensional vectors.
Definition: math_util.h:196
nec_float norm() const
The Euclidian norm.
Definition: math_util.h:207
static void int_solve(nec_3vector &a0, nec_3vector &a1, nec_3vector &b0, nec_3vector &b1, nec_float &distance, nec_float &sa, nec_float &sb)
Definition: nec_wire.h:215
std::vector< nec_wire > intersect(nec_wire &b)
Calculate whether two wires intersect.
Definition: nec_wire.h:60