Ajout des fonction insetProportionnal pour Triangle et Quad, ainsi que
de fonctions utilisateire dans Segment.
This commit is contained in:
parent
d764489f30
commit
18febfa792
|
@ -223,6 +223,19 @@ float Quad::surface() const {
|
||||||
return ne.surface() + sw.surface();
|
return ne.surface() + sw.surface();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Quad Quad::insetProportionnal(float prop) {
|
||||||
|
Quad rQuad= *this;
|
||||||
|
|
||||||
|
Vertex bc = Segment(Segment(c[NW],c[NE]).center(),Segment(c[SW],c[SE]).center()).center();
|
||||||
|
prop = prop;
|
||||||
|
|
||||||
|
rQuad[NW] = Segment(bc,c[NW]).at(prop);
|
||||||
|
rQuad[NE] = Segment(bc,c[NE]).at(prop);
|
||||||
|
rQuad[SE] = Segment(bc,c[SE]).at(prop);
|
||||||
|
rQuad[SW] = Segment(bc,c[SW]).at(prop);
|
||||||
|
return rQuad;
|
||||||
|
}
|
||||||
|
|
||||||
Quad Quad::offsetNormal(float offset) const {
|
Quad Quad::offsetNormal(float offset) const {
|
||||||
return ((*this) + Triangle(c[NE], c[SE], c[SW]).normal().setNorm(offset));
|
return ((*this) + Triangle(c[NE], c[SE], c[SW]).normal().setNorm(offset));
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ class Quad {
|
||||||
float surface() const;
|
float surface() const;
|
||||||
//void cutCornerCorner(Coin from) const;
|
//void cutCornerCorner(Coin from) const;
|
||||||
Quad makeParallelogram() const;
|
Quad makeParallelogram() const;
|
||||||
|
Quad insetProportionnal(float prop);
|
||||||
Quad offsetNormal(float offset) const;
|
Quad offsetNormal(float offset) const;
|
||||||
Vertex normal() const;
|
Vertex normal() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,6 +11,14 @@ Segment Segment::reduce(float value) {
|
||||||
return Segment(u,u+((v - u) / reduc));
|
return Segment(u,u+((v - u) / reduc));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vertex Segment::at(float proportiannalDist) {
|
||||||
|
return Segment(u,u+((v-u)*proportiannalDist)).v;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vertex Segment::center() {
|
||||||
|
return at(1./2.);
|
||||||
|
}
|
||||||
|
|
||||||
float Segment::width() {
|
float Segment::width() {
|
||||||
return std::abs(u.x - v.x);
|
return std::abs(u.x - v.x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ class Segment {
|
||||||
float length();
|
float length();
|
||||||
float width();
|
float width();
|
||||||
float height();
|
float height();
|
||||||
|
Vertex center();
|
||||||
|
Vertex at(float);
|
||||||
Segment reduce(float value);
|
Segment reduce(float value);
|
||||||
Vertex randomPos(int seed, int n, float a, float b); // Renvoie un vertex sur le segment [u,v], à une position entre a et b.
|
Vertex randomPos(int seed, int n, float a, float b); // Renvoie un vertex sur le segment [u,v], à une position entre a et b.
|
||||||
};
|
};
|
||||||
|
|
|
@ -99,3 +99,21 @@ Vertex Triangle::normalizedNormal() const {
|
||||||
Triangle Triangle::offsetNormal(float offset) const {
|
Triangle Triangle::offsetNormal(float offset) const {
|
||||||
return ((*this) + this->normal().setNorm(offset));
|
return ((*this) + this->normal().setNorm(offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Triangle Triangle::insetProportionnal(float prop) {
|
||||||
|
Triangle rTriangle = *this;
|
||||||
|
//ibc : isobarycentre.
|
||||||
|
Vertex ibc = Segment(c[TOP],Segment(c[LEFT],c[RIGHT]).center()).at(2./3.);
|
||||||
|
prop = prop;
|
||||||
|
|
||||||
|
rTriangle[TOP] = Segment(ibc,c[TOP]).at(prop);
|
||||||
|
rTriangle[LEFT] = Segment(ibc,c[LEFT]).at(prop);
|
||||||
|
rTriangle[RIGHT] = Segment(ibc,c[RIGHT]).at(prop);
|
||||||
|
return rTriangle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ public :
|
||||||
Vertex normal() const;
|
Vertex normal() const;
|
||||||
Vertex normalizedNormal() const;
|
Vertex normalizedNormal() const;
|
||||||
Triangle offsetNormal(float offset) const;
|
Triangle offsetNormal(float offset) const;
|
||||||
|
Triangle insetProportionnal(float prop);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user