27 o <<
"***********" << std::endl;
28 o <<
"a_triangle:" << std::endl;
29 o <<
"***********" << std::endl;
30 o <<
"This is a 'triangle' class" << std::endl;
32 o <<
"Create a triangle:" << std::endl;
33 o <<
" a_triangle a" << std::endl;
34 o <<
" a_triangle a _p1 _p2 _p3" << std::endl;
36 o <<
"Commands:" << std::endl;
37 o <<
"p1, p2, p3: get or set apices" << std::endl;
38 o <<
"s1, s2, s3: returns sides of triangle as segments" << std::endl;
39 o <<
"s _ref: returns sides of triangle as segments" << std::endl;
40 o <<
"c: get centre" << std::endl;
41 o <<
"translate _x _y _z: translate." << std::endl;
42 o <<
"rotate _xaxis _yaxis _zaxis: rotate." << std::endl;
43 o <<
"invert: inverts orientation (p2 and p3)." << std::endl;
44 o <<
"normal: get normal vector" << std::endl;
45 o <<
"contains _pt: check whether contains point" << std::endl;
46 o <<
"closest _pt: triangle point closest to p" << std::endl;
47 o <<
"closestp _pt: point of plane defined by triangle closest to p" << std::endl;
48 o <<
"dist _pt: distance between p and triangle" << std::endl;
49 o <<
"distp _pt: distance between p and plane defined by triangle" << std::endl;
50 o <<
"intersect _seg: intersection of triangle with a segment" << std::endl;
51 o <<
"min_edge: length of shortest edge" << std::endl;
52 o <<
"max_edge: length of longest edge" << std::endl;
53 o <<
"quality: ratio between the shortest and longest edge" << std::endl;
60 return ((
p1_ ==
p.p1())&&(
p2_ ==
p.p2())&&(
p3_ ==
p.p3()));
73 if (ref==0)
return this->
s1();
74 else if (ref==1)
return this->
s2();
121 for (
short i = 0; i<3; i++)
124 for (
short j = 0; j<3; j++)
135 double S = this->
S();
138 for (
short i = 0; i<2; i++)
141 s(i,(i+1)%2) = -1./72.;
147 for (
short i = 0; i<2; i++)
149 v(i,0) = -2.*
p1[i]-
p2[i];
150 v(i,1) = -
p1[i]+
p2[i];
182 double det = a11*a22-a12*a12;
184 double u = (a22*
p1-a12*
p2)/det;
185 double v = (-a12*
p1+a11*
p2)/det;
212 double d1 = (
p-
p1).norm();
213 double d2 = (
p-
p2).norm();
214 double d3 = (
p-
p3).norm();
215 if ((d1<d2)&&(d1<d3))
217 if ((d2<d1)&&(d2<d3))
237 double d1 = this->
distp(p1);
238 double d2 = this->
distp(p2);
250 std::vector<a_point> list;
259 list.push_back(i1.
c());
261 list.push_back(i2.
c());
263 list.push_back(i3.
c());
333 o << this->
p1() <<
" ";
334 o << this->
p2() <<
" ";
335 o << this->
p3() <<
" ";
a_point cross(const a_point &a, const a_point &b)
static const std::string help()
a_point closest(const a_point &p) const
point on the plane closest to p
a_point & rotate(const a_point &x_axis, const a_point &y_axis, const a_point &z_axis)
a_point & translate(double x, double y, double z)
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_point c() const
center of segment
a_point p2() const
get second apex of segment
a_point closest(const a_point &p) const
point closest to p inside segment
a_point p1() const
get first apex of segment
a_triangle & rotate(const a_point &x_axis, const a_point &y_axis, const a_point &z_axis)
double max_edge() const
length of longest segment
static const std::string help()
a_point p(const int i) const
virtual void read(std::istream &i)
bool operator==(const a_triangle &p)
virtual void write(std::ostream &o) const
a_triangle & operator=(const a_triangle &p)
bool contains(const a_point &p) const
check whether point lies inside triangle
a_segment s(const int ref) const
get segment i (0-2) of triangle
a_triangle shape() const
triangle with same shape but with centre of gravity at origin
a_point closest(const a_point &p) const
triangle point closest to p
a_segment s2() const
get second segment of triangle
a_segment s1() const
get first segment of triangle
a_mat_sq inertia() const
inertia of the triangle 3x3 matrix
double quality() const
quality: ratio between smaller and bigger segment
a_point c() const
get centre of gravity
double min_edge() const
length of smallest segment
a_segment s3() const
get third segment of triangle
a_segment intersect(const a_segment &s) const
intersection of triangle with a segment
a_triangle & translate(double x, double y, double z)
double distp(const a_point &p) const
distance between p and plane defined by triangle
a_mat_sq coord() const
cordinates of the triangle as a 3x3 matrix
double dist(const a_point &p) const
distance between p and triangle
a_point closestp(const a_point &p) const
point of plane defined by triangle closest to p