28 o <<
"**********" << std::endl;
29 o <<
"a_segment:" << std::endl;
30 o <<
"**********" << std::endl;
31 o <<
"This is a 'segment' class." << std::endl;
33 o <<
"Create a segment:" << std::endl;
34 o <<
" a_point a 0 0 0" << std::endl;
35 o <<
" a_point b 1 0 0" << std::endl;
36 o <<
" a_segment s1 a b" << std::endl;
37 o <<
" set s2 [a_segment [new_a_point 0 0 0] [new_a_point 0 1 0] ]" << std::endl;
39 o <<
"Commands:" << std::endl;
40 o <<
"p1, p2, p1 _pt, p2 _pt: returns or set apices." << std::endl;
41 o <<
"c: returns centre."<< std::endl;
42 o <<
"vec: returns p2-p1."<< std::endl;
43 o <<
"dir: returns direction (normalised)."<< std::endl;
44 o <<
"translate _x _y _z: move segment."<< std::endl;
45 o <<
"rotate _xaxis _yaxis _zaxis: rotate segment; 3 points define new axis."<< std::endl;
46 o <<
"length: returns length of segment." << std::endl;
47 o <<
"project _pt: project a point on the segment."<< std::endl;
48 o <<
"closest _pt: returns pt closest to _pt belonging to segment."<< std::endl;
49 o <<
"closestl _pt: returns pt closest to _pt on line defined by segment."<< std::endl;
50 o <<
"dist _pt: closest distance to _pt."<< std::endl;
51 o <<
"dist _seg: closest distance to _seg."<< std::endl;
52 o <<
"distl _pt: closest distance between _pt and line defined by segment."<< std::endl;
53 o <<
"distl _seg: closest distance between lines defined by segments."<< std::endl;
54 o <<
"intersect _seg _m1* _m2*: intersection between to segments; returns a segment between the closest point between the two lines (l1,l2) defined by the segment; also returns the relative position (0-1 if inside segments) of its apices on l1 and l2." << std::endl;
55 o <<
"shortest _seg _m1* _m2*: shortest distance between two lines defined by segments; returns a segment between the closest point between the two segments; also returns the relative position of its apices on the input segments."<< std::endl;
56 o <<
"print: print segment parameters (coordinates of apices)."<< std::endl;
87 for (
short i=0; i<3; i++)
91 for (
short j=0; j<=i; j++)
95 double v = l*(li*lj/12.+ci*cj);
141 const double eps = 1e-10;
156 m2 = (b>
c ? d/b : e/
c);
179 const double eps = 1e-10;
186 double sd1d2 = d2*d1;
188 double sd1dor = dor*d1;
189 double sd2dor = dor*d2;
190 double D = (sd1*sd2-sd1d2*sd1d2);
198 m1 = (sd1d2*sd2dor-sd2*sd1dor) / D;
199 m2 = (sd1*sd2dor-sd1d2*sd1dor) / D;
201 if ((m1<0)||(m1>1)||(m2<0)||(m2>1))
203 std::vector<pack> li;
213 std::sort(li.begin(),li.end());
214 int ref = li[0].ref_;
220 m1 = ((pn-
p1_)*d1)/sd1;
225 m1 = ((pn-
p1_)*d1)/sd1;
231 m2 = ((pn-s.
p1())*d2)/sd2;
236 m2 = ((pn-s.
p1())*d2)/sd2;
386 o << this->
p1() <<
" ";
387 o << this->
p2() <<
" ";
double dist(const a_point &a, const a_point &b)
bool operator<(const pack &p1, const pack &p2)
static const std::string help()
a_point & rotate(const a_point &x_axis, const a_point &y_axis, const a_point &z_axis)
double dist(const a_point &p) const
bool operator==(const a_segment &p)
double dist(const a_point &p) const
distance betweeen p and segment
static const std::string help()
a_point dir() const
get direction defined by segment
a_point vec() const
get vector between the two apices
a_segment shortest(const a_segment &s, double &m1, double &m2) const
intersection between two segments, returns a segment between the closest point between the two segmen...
a_segment & rotate(const a_point &x_axis, const a_point &y_axis, const a_point &z_axis)
double project(const a_point v) const
a_point c() const
center of segment
virtual void read(std::istream &i)
a_mat_sq inertia() const
inertia of the segment
a_segment intersect(const a_segment &s, double &m1, double &m2) const
intersection between two segments, returns a segment between the closest point between the two lines ...
a_point closestl(const a_point &p) const
point closest to p on line defined by segment
a_point p2() const
get second apex of segment
a_point closest(const a_point &p) const
point closest to p inside segment
double distl(const a_point &p) const
distance between p and line defined by segment
a_segment & operator=(const a_segment &v)
virtual void write(std::ostream &o) const
a_point p1() const
get first apex of segment
pack(int ref, double dist)