|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tmachine.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcurves.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tcurveutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tmathutil.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tbezier.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace std;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ostream &operator<<(ostream &out, const TSegment &segment)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return out << "S{" << segment.getP0() << ", " << segment.getP1() << "}";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TCubic::split(double t, TCubic &first, TCubic &second) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double s = 1.0 - t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD H = s * m_p1 + t * m_p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
first.m_p0 = m_p0;
|
|
Toshihiro Shimizu |
890ddd |
first.m_p1 = s * m_p0 + t * m_p1;
|
|
Toshihiro Shimizu |
890ddd |
first.m_p2 = s * first.m_p1 + t * H;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
second.m_p3 = m_p3;
|
|
Toshihiro Shimizu |
890ddd |
second.m_p2 = s * m_p2 + t * m_p3;
|
|
Toshihiro Shimizu |
890ddd |
second.m_p1 = s * H + t * second.m_p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
first.m_p3 = s * first.m_p2 + t * second.m_p1;
|
|
Toshihiro Shimizu |
890ddd |
second.m_p0 = first.m_p3;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double TCubic::getLength(double t0, double t1) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return -1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD TQuadratic::getPoint(double t) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double s = 1 - t;
|
|
Toshihiro Shimizu |
890ddd |
return m_p0 * s * s + 2 * t * s * m_p1 + t * t * m_p2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double TQuadratic::getX(double t) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double s = 1 - t;
|
|
Toshihiro Shimizu |
890ddd |
return m_p0.x * s * s + 2 * t * s * m_p1.x + t * t * m_p2.x;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double TQuadratic::getY(double t) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double s = 1 - t;
|
|
Toshihiro Shimizu |
890ddd |
return m_p0.y * s * s + 2 * t * s * m_p1.y + t * t * m_p2.y;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double TQuadratic::getT(const TPointD &p) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// risolvo l'equazione min|| b(t) - p ||
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// esprimo b in forma di polinomio ed ottengo
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// || 2 ||
|
|
Toshihiro Shimizu |
890ddd |
//min || a t + b t + c - p ||
|
|
Toshihiro Shimizu |
890ddd |
// || ||
|
|
Toshihiro Shimizu |
890ddd |
//
|
|
Toshihiro Shimizu |
890ddd |
// il tutto si riconduce a cercare le radici
|
|
Toshihiro Shimizu |
890ddd |
// di un'equazione del tipo
|
|
Toshihiro Shimizu |
890ddd |
// 2 3 2 2
|
|
Toshihiro Shimizu |
890ddd |
// 2·a ·t + 3·a·b·t + t·(2·a·v + b ) + b·v
|
|
Toshihiro Shimizu |
890ddd |
// dove v e' pari a c - p
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vector<tpointd></tpointd>
|
|
Toshihiro Shimizu |
890ddd |
bez(3),
|
|
Toshihiro Shimizu |
890ddd |
poly(3);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bez[0] = m_p0;
|
|
Toshihiro Shimizu |
890ddd |
bez[1] = m_p1;
|
|
Toshihiro Shimizu |
890ddd |
bez[2] = m_p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bezier2poly(bez, poly);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD v = poly[0] - p;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
vector<double> toSolve(4);</double>
|
|
Toshihiro Shimizu |
890ddd |
vector<double> sol;</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
toSolve[3] = 2.0 * norm2(poly[2]);
|
|
Toshihiro Shimizu |
890ddd |
toSolve[2] = 3.0 * (poly[2].x * poly[1].x + poly[2].y * poly[1].y);
|
|
Toshihiro Shimizu |
890ddd |
toSolve[1] = 2.0 * (poly[2].x * v.x + poly[2].y * v.y) + norm2(poly[1]);
|
|
Toshihiro Shimizu |
890ddd |
toSolve[0] = (poly[1].x * v.x + poly[1].y * v.y);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int nSol = rootFinding(toSolve, sol);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (-1 == nSol) // infinite soluzioni
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int minParameter = -1;
|
|
Toshihiro Shimizu |
890ddd |
double minDist = (std::numeric_limits<double>::max)();</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int i = 0; i < nSol; ++i) {
|
|
Toshihiro Shimizu |
890ddd |
if (sol[i] < 0.0)
|
|
Toshihiro Shimizu |
890ddd |
sol[i] = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
else if (sol[i] > 1.0)
|
|
Toshihiro Shimizu |
890ddd |
sol[i] = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double tmpDist = tdistance2(p, getPoint(sol[i]));
|
|
Toshihiro Shimizu |
890ddd |
if (tmpDist < minDist) {
|
|
Toshihiro Shimizu |
890ddd |
minDist = tmpDist;
|
|
Toshihiro Shimizu |
890ddd |
minParameter = i;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (minParameter != -1)
|
|
Toshihiro Shimizu |
890ddd |
return sol[minParameter];
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return tdistance2(m_p0, p) < tdistance2(m_p2, p) ? 0 : 1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TQuadratic::split(double t, TQuadratic &left, TQuadratic &right) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double dt;
|
|
Toshihiro Shimizu |
890ddd |
TPointD p;
|
|
Toshihiro Shimizu |
890ddd |
dt = 1.0 - t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
left.m_p0 = m_p0;
|
|
Toshihiro Shimizu |
890ddd |
right.m_p2 = m_p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
left.m_p1 = dt * m_p0 + t * m_p1;
|
|
Toshihiro Shimizu |
890ddd |
right.m_p1 = dt * m_p1 + t * m_p2;
|
|
Toshihiro Shimizu |
890ddd |
p = dt * left.m_p1 + t * right.m_p1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
left.m_p2 = right.m_p0 = p;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectD TQuadratic::getBBox() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TRectD bBox;
|
|
Toshihiro Shimizu |
890ddd |
if (m_p0.x < m_p2.x)
|
|
Toshihiro Shimizu |
890ddd |
bBox.x0 = m_p0.x, bBox.x1 = m_p2.x;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
bBox.x0 = m_p2.x, bBox.x1 = m_p0.x;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (m_p0.y < m_p2.y)
|
|
Toshihiro Shimizu |
890ddd |
bBox.y0 = m_p0.y, bBox.y1 = m_p2.y;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
bBox.y0 = m_p2.y, bBox.y1 = m_p0.y;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD denom = 2 * m_p1 - m_p0 - m_p2;
|
|
Toshihiro Shimizu |
890ddd |
if (denom.x != 0) {
|
|
Toshihiro Shimizu |
890ddd |
double tx = (m_p1.x - m_p0.x) / denom.x;
|
|
Toshihiro Shimizu |
890ddd |
if (tx >= 0 && tx <= 1) {
|
|
Toshihiro Shimizu |
890ddd |
double x = getPoint(tx).x;
|
|
Toshihiro Shimizu |
890ddd |
if (x < bBox.x0)
|
|
Toshihiro Shimizu |
890ddd |
bBox.x0 = x;
|
|
Toshihiro Shimizu |
890ddd |
else if (x > bBox.x1)
|
|
Toshihiro Shimizu |
890ddd |
bBox.x1 = x;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (denom.y != 0) {
|
|
Toshihiro Shimizu |
890ddd |
double ty = (m_p1.y - m_p0.y) / denom.y;
|
|
Toshihiro Shimizu |
890ddd |
if (ty >= 0 && ty <= 1) {
|
|
Toshihiro Shimizu |
890ddd |
double y = getPoint(ty).y;
|
|
Toshihiro Shimizu |
890ddd |
if (y < bBox.y0)
|
|
Toshihiro Shimizu |
890ddd |
bBox.y0 = y;
|
|
Toshihiro Shimizu |
890ddd |
else if (y > bBox.y1)
|
|
Toshihiro Shimizu |
890ddd |
bBox.y1 = y;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return bBox;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*!
|
|
Toshihiro Shimizu |
890ddd |
Calcolo della curvatura per una Quadratica.
|
|
Toshihiro Shimizu |
890ddd |
Vedi Farin pag.176 per la spiegazione della formula
|
|
Toshihiro Shimizu |
890ddd |
usata.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
double TQuadratic::getCurvature(double t) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(0 <= t && t <= 1.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TQuadratic q1, q2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
split(t, q1, q2);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double signum = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
if (areAlmostEqual(t, 1.0)) {
|
|
Toshihiro Shimizu |
890ddd |
signum *= -1.0;
|
|
Toshihiro Shimizu |
890ddd |
std::swap(q1, q2);
|
|
Toshihiro Shimizu |
890ddd |
std::swap(q2.m_p0, q2.m_p2);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD v_1_0(q2.m_p1 - q2.m_p0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double
|
|
Toshihiro Shimizu |
890ddd |
a = norm2(v_1_0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (isAlmostZero(a))
|
|
Toshihiro Shimizu |
890ddd |
return (std::numeric_limits<double>::max)();</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
a = 1.0 / sqrt(a);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double
|
|
Toshihiro Shimizu |
890ddd |
b = cross(v_1_0 * a, q2.m_p2 - q2.m_p0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return 0.5 * signum * b / a;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double TQuadratic::getLength(double t0, double t1) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TQuadraticLengthEvaluator lengthEval(*this);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
t0 = min(max(0.0, t0), 1.0); // backward compatibility
|
|
Toshihiro Shimizu |
890ddd |
t1 = min(max(0.0, t1), 1.0); // backward compatibility
|
|
Toshihiro Shimizu |
890ddd |
if (t0 > t1)
|
|
Toshihiro Shimizu |
890ddd |
std::swap(t0, t1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (t0 > 0.0)
|
|
Toshihiro Shimizu |
890ddd |
return lengthEval.getLengthAt(t1) - lengthEval.getLengthAt(t0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return lengthEval.getLengthAt(t1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double TQuadratic::getApproximateLength(double t0, double t1, double error) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (t0 == t1)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
t0 = min(max(0.0, t0), 1.0);
|
|
Toshihiro Shimizu |
890ddd |
t1 = min(max(0.0, t1), 1.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (t0 > t1)
|
|
Toshihiro Shimizu |
890ddd |
std::swap(t0, t1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TQuadratic q;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (t0 == 0.0 && t1 == 1.0)
|
|
Toshihiro Shimizu |
890ddd |
q = *this;
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TQuadratic q1;
|
|
Toshihiro Shimizu |
890ddd |
split(t0, q, q1);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
assert(t0 != 1.0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double newPar = (t1 - t0) / (1.0 - t0);
|
|
Toshihiro Shimizu |
890ddd |
q1.split(newPar, q, q1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double step = computeStep(q, error);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double length = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD p1 = q.getP0();
|
|
Toshihiro Shimizu |
890ddd |
TPointD p2;
|
|
Toshihiro Shimizu |
890ddd |
for (double t = step; t < 1.0; t += step) {
|
|
Toshihiro Shimizu |
890ddd |
p2 = q.getPoint(t);
|
|
Toshihiro Shimizu |
890ddd |
length += tdistance(p1, p2);
|
|
Toshihiro Shimizu |
890ddd |
p1 = p2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
length += tdistance(p1, q.getP2());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return length;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TQuadratic::getX(double y, double &x0, double &x1) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int ret = 0;
|
|
Toshihiro Shimizu |
890ddd |
double t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (y > getBBox().y1 || y < getBBox().y0)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double a = getP0().y - 2 * getP1().y + getP2().y;
|
|
Toshihiro Shimizu |
890ddd |
double half_b = getP1().y - getP0().y;
|
|
Toshihiro Shimizu |
890ddd |
double c = getP0().y - y;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (a == 0) //segment
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (half_b == 0) //horizontal segment, or point
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (c == 0) {
|
|
Toshihiro Shimizu |
890ddd |
x0 = getP0().x;
|
|
Toshihiro Shimizu |
890ddd |
x1 = getP2().x;
|
|
Toshihiro Shimizu |
890ddd |
return 2;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
t = -c / (2 * half_b);
|
|
Toshihiro Shimizu |
890ddd |
if (t >= 0 && t <= 1) {
|
|
Toshihiro Shimizu |
890ddd |
x0 = getPoint(t).x;
|
|
Toshihiro Shimizu |
890ddd |
return 1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double discr = half_b * half_b - a * c;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (discr < 0)
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double coeff = 1.0 / a;
|
|
Toshihiro Shimizu |
890ddd |
double coeff1 = -half_b * coeff;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (discr == 0) {
|
|
Toshihiro Shimizu |
890ddd |
t = coeff1;
|
|
Toshihiro Shimizu |
890ddd |
if (t >= 0 && t <= 1) {
|
|
Toshihiro Shimizu |
890ddd |
ret = 2;
|
|
Toshihiro Shimizu |
890ddd |
x0 = x1 = getPoint(t).x;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
discr = sqrt(discr) * coeff;
|
|
Toshihiro Shimizu |
890ddd |
t = coeff1 + discr;
|
|
Toshihiro Shimizu |
890ddd |
if (t >= 0 && t <= 1) {
|
|
Toshihiro Shimizu |
890ddd |
ret++;
|
|
Toshihiro Shimizu |
890ddd |
x0 = getPoint(t).x;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
t = coeff1 - discr;
|
|
Toshihiro Shimizu |
890ddd |
if (t >= 0 && t <= 1) {
|
|
Toshihiro Shimizu |
890ddd |
ret++;
|
|
Toshihiro Shimizu |
890ddd |
if (ret == 2)
|
|
Toshihiro Shimizu |
890ddd |
x1 = getPoint(t).x;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
x0 = getPoint(t).x;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return ret;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int TQuadratic::getY(double y, double &y0, double &y1) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
TQuadratic temp(*this);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
swap(temp.m_p0.x, temp.m_p0.y);
|
|
Toshihiro Shimizu |
890ddd |
swap(temp.m_p1.x, temp.m_p1.y);
|
|
Toshihiro Shimizu |
890ddd |
swap(temp.m_p2.x, temp.m_p2.y);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return temp.getX(y, y0, y1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
TPointD TCubic::getPoint(double t) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double s = 1 - t;
|
|
Toshihiro Shimizu |
890ddd |
return m_p0 * s * s * s + 3 * t * s * (s * m_p1 + t * m_p2) + t * t * t * m_p3;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
TPointD TCubic::getSpeed(double t) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double s = 1 - t;
|
|
Toshihiro Shimizu |
890ddd |
return 3.0 * ((m_p1 - m_p0) * s * s + 2 * (m_p2 - m_p0) * s * t + (m_p3 - m_p2) * t * t);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickQuadratic::TThickQuadratic()
|
|
Toshihiro Shimizu |
890ddd |
: TQuadratic(), m_thickP0(0), m_thickP1(0), m_thickP2(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickQuadratic::TThickQuadratic(const TQuadratic &q)
|
|
Toshihiro Shimizu |
890ddd |
: TQuadratic(q), m_thickP0(0.0), m_thickP1(0.0), m_thickP2(0.0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickQuadratic::TThickQuadratic(const TPointD &p0, double thickP0,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p1, double thickP1,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p2, double thickP2)
|
|
Toshihiro Shimizu |
890ddd |
: TQuadratic(p0, p1, p2), m_thickP0(thickP0), m_thickP1(thickP1), m_thickP2(thickP2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickQuadratic::TThickQuadratic(const TThickPoint &p0,
|
|
Toshihiro Shimizu |
890ddd |
const TThickPoint &p1,
|
|
Toshihiro Shimizu |
890ddd |
const TThickPoint &p2)
|
|
Toshihiro Shimizu |
890ddd |
: TQuadratic(TPointD(p0.x, p0.y), TPointD(p1.x, p1.y), TPointD(p2.x, p2.y)), m_thickP0(p0.thick), m_thickP1(p1.thick), m_thickP2(p2.thick)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickQuadratic::TThickQuadratic(const TThickQuadratic &thickQuadratic)
|
|
Toshihiro Shimizu |
890ddd |
: TQuadratic(thickQuadratic), m_thickP0(thickQuadratic.m_thickP0), m_thickP1(thickQuadratic.m_thickP1), m_thickP2(thickQuadratic.m_thickP2)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
void TThickQuadratic::setThickP0(const TThickPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_p0 = p;
|
|
Toshihiro Shimizu |
890ddd |
m_thickP0 = p.thick;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
void TThickQuadratic::setThickP1(const TThickPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_p1 = p;
|
|
Toshihiro Shimizu |
890ddd |
m_thickP1 = p.thick;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
void TThickQuadratic::setThickP2(const TThickPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_p2 = p;
|
|
Toshihiro Shimizu |
890ddd |
m_thickP2 = p.thick;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint TThickQuadratic::getThickPoint(double t) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double s = 1 - t;
|
|
Toshihiro Shimizu |
890ddd |
return TThickPoint(m_p0 * s * s + 2 * t * s * m_p1 + t * t * m_p2, m_thickP0 * s * s + 2 * t * s * m_thickP1 + t * t * m_thickP2);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
void TThickQuadratic::split(double t, TThickQuadratic &left, TThickQuadratic &right) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double dt;
|
|
Toshihiro Shimizu |
890ddd |
TPointD p;
|
|
Toshihiro Shimizu |
890ddd |
dt = 1.0 - t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// control points
|
|
Toshihiro Shimizu |
890ddd |
left.m_p0 = m_p0;
|
|
Toshihiro Shimizu |
890ddd |
right.m_p2 = m_p2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
left.m_p1 = dt * m_p0 + t * m_p1;
|
|
Toshihiro Shimizu |
890ddd |
right.m_p1 = dt * m_p1 + t * m_p2;
|
|
Toshihiro Shimizu |
890ddd |
p = dt * left.m_p1 + t * right.m_p1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
left.m_p2 = right.m_p0 = p;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// thick points
|
|
Toshihiro Shimizu |
890ddd |
left.m_thickP0 = m_thickP0;
|
|
Toshihiro Shimizu |
890ddd |
right.m_thickP2 = m_thickP2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
left.m_thickP1 = dt * m_thickP0 + t * m_thickP1;
|
|
Toshihiro Shimizu |
890ddd |
right.m_thickP1 = dt * m_thickP1 + t * m_thickP2;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// store thickness of intermediary point
|
|
Toshihiro Shimizu |
890ddd |
p.x = dt * left.m_thickP1 + t * right.m_thickP1;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
left.m_thickP2 = right.m_thickP0 = p.x;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectD TThickQuadratic::getBBox() const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRectD bBox = TQuadratic::getBBox();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double maxRadius = tmax(m_thickP0, m_thickP1, m_thickP2);
|
|
Toshihiro Shimizu |
890ddd |
if (maxRadius > 0) {
|
|
Toshihiro Shimizu |
890ddd |
// bBox.enlarge(maxRadius) si comporta male nel caso bBox.isEmpty()
|
|
Toshihiro Shimizu |
890ddd |
bBox.x0 -= maxRadius;
|
|
Toshihiro Shimizu |
890ddd |
bBox.y0 -= maxRadius;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bBox.x1 += maxRadius;
|
|
Toshihiro Shimizu |
890ddd |
bBox.y1 += maxRadius;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return bBox;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// ============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// Methods of the class TThickCubic
|
|
Toshihiro Shimizu |
890ddd |
// ============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickCubic::TThickCubic()
|
|
Toshihiro Shimizu |
890ddd |
: TCubic(), m_thickP0(0), m_thickP1(0), m_thickP2(0), m_thickP3(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickCubic::TThickCubic(const TPointD &p0, double thickP0,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p1, double thickP1,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p2, double thickP2,
|
|
Toshihiro Shimizu |
890ddd |
const TPointD &p3, double thickP3)
|
|
Toshihiro Shimizu |
890ddd |
: TCubic(p0, p1, p2, p3), m_thickP0(thickP0), m_thickP1(thickP1), m_thickP2(thickP2), m_thickP3(thickP3)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickCubic::TThickCubic(const TThickPoint &p0,
|
|
Toshihiro Shimizu |
890ddd |
const TThickPoint &p1,
|
|
Toshihiro Shimizu |
890ddd |
const TThickPoint &p2,
|
|
Toshihiro Shimizu |
890ddd |
const TThickPoint &p3)
|
|
Toshihiro Shimizu |
890ddd |
: TCubic(TPointD(p0.x, p0.y), TPointD(p1.x, p1.y), TPointD(p2.x, p2.y), TPointD(p3.x, p3.y)), m_thickP0(p0.thick), m_thickP1(p1.thick), m_thickP2(p2.thick), m_thickP3(p3.thick)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
// tonino ***************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickCubic::TThickCubic(const T3DPointD &p0,
|
|
Toshihiro Shimizu |
890ddd |
const T3DPointD &p1,
|
|
Toshihiro Shimizu |
890ddd |
const T3DPointD &p2,
|
|
Toshihiro Shimizu |
890ddd |
const T3DPointD &p3)
|
|
Toshihiro Shimizu |
890ddd |
: TCubic(TPointD(p0.x, p0.y), TPointD(p1.x, p1.y), TPointD(p2.x, p2.y), TPointD(p3.x, p3.y)), m_thickP0(p0.z), m_thickP1(p1.z), m_thickP2(p2.z), m_thickP3(p3.z)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// tonino ***************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickCubic::TThickCubic(const TThickCubic &thickCubic)
|
|
Toshihiro Shimizu |
890ddd |
: TCubic(thickCubic), m_thickP0(thickCubic.m_thickP0), m_thickP1(thickCubic.m_thickP1), m_thickP2(thickCubic.m_thickP2), m_thickP3(thickCubic.m_thickP3)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TThickCubic::setThickP0(const TThickPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_p0.x = p.x;
|
|
Toshihiro Shimizu |
890ddd |
m_p0.y = p.y;
|
|
Toshihiro Shimizu |
890ddd |
m_thickP0 = p.thick;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TThickCubic::setThickP1(const TThickPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_p1.x = p.x;
|
|
Toshihiro Shimizu |
890ddd |
m_p1.y = p.y;
|
|
Toshihiro Shimizu |
890ddd |
m_thickP1 = p.thick;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TThickCubic::setThickP2(const TThickPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_p2.x = p.x;
|
|
Toshihiro Shimizu |
890ddd |
m_p2.y = p.y;
|
|
Toshihiro Shimizu |
890ddd |
m_thickP2 = p.thick;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
void TThickCubic::setThickP3(const TThickPoint &p)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_p3.x = p.x;
|
|
Toshihiro Shimizu |
890ddd |
m_p3.y = p.y;
|
|
Toshihiro Shimizu |
890ddd |
m_thickP3 = p.thick;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TThickPoint TThickCubic::getThickPoint(double t) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double
|
|
Toshihiro Shimizu |
890ddd |
thick_l1,
|
|
Toshihiro Shimizu |
890ddd |
thick_h,
|
|
Toshihiro Shimizu |
890ddd |
thick_r3;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double s = 1.0 - t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD l1(m_p0 * s + m_p1 * t);
|
|
Toshihiro Shimizu |
890ddd |
thick_l1 = m_thickP0 * s + m_thickP1 * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD h(m_p1 * s + m_p2 * t);
|
|
Toshihiro Shimizu |
890ddd |
thick_h = m_thickP1 * s + m_thickP2 * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD r3(m_p2 * s + m_p3 * t);
|
|
Toshihiro Shimizu |
890ddd |
thick_r3 = m_thickP2 * s + m_thickP3 * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// adesso riutilizzo le variabili gia' utilizzate
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// l2
|
|
Toshihiro Shimizu |
890ddd |
l1 = l1 * s + h * t;
|
|
Toshihiro Shimizu |
890ddd |
thick_l1 = thick_l1 * s + thick_h * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// r1
|
|
Toshihiro Shimizu |
890ddd |
r3 = h * s + r3 * t;
|
|
Toshihiro Shimizu |
890ddd |
thick_r3 = thick_h * s + thick_r3 * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// l3-r0
|
|
Toshihiro Shimizu |
890ddd |
h = l1 * s + r3 * t;
|
|
Toshihiro Shimizu |
890ddd |
thick_h = thick_l1 * s + thick_r3 * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
return TThickPoint(h, thick_h);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TThickCubic::split(double t, TThickCubic &first, TThickCubic &second) const
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double s = 1.0 - t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TPointD H(m_p1 * s + m_p2 * t);
|
|
Toshihiro Shimizu |
890ddd |
double thick_h = m_thickP1 * s + m_thickP2 * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
first.m_p0 = m_p0;
|
|
Toshihiro Shimizu |
890ddd |
first.m_thickP0 = m_thickP0;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
first.m_p1 = m_p0 * s + m_p1 * t;
|
|
Toshihiro Shimizu |
890ddd |
first.m_thickP1 = m_thickP0 * s + m_thickP1 * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
first.m_p2 = first.m_p1 * s + H * t;
|
|
Toshihiro Shimizu |
890ddd |
first.m_thickP2 = first.m_thickP1 * s + thick_h * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
second.m_p3 = m_p3;
|
|
Toshihiro Shimizu |
890ddd |
second.m_thickP3 = m_thickP3;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
second.m_p2 = m_p2 * s + m_p3 * t;
|
|
Toshihiro Shimizu |
890ddd |
second.m_thickP2 = m_thickP2 * s + m_thickP3 * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
second.m_p1 = H * s + second.m_p2 * t;
|
|
Toshihiro Shimizu |
890ddd |
second.m_thickP1 = thick_h * s + second.m_thickP2 * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
first.m_p3 = first.m_p2 * s + second.m_p1 * t;
|
|
Toshihiro Shimizu |
890ddd |
first.m_thickP3 = first.m_thickP2 * s + second.m_thickP1 * t;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
second.m_p0 = first.m_p3;
|
|
Toshihiro Shimizu |
890ddd |
second.m_thickP0 = first.m_thickP3;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ostream &operator<<(ostream &out, const TQuadratic &curve)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return out << "Q{" << curve.getP0() << ", " << curve.getP1() << ", "
|
|
Toshihiro Shimizu |
890ddd |
<< curve.getP2() << "}";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ostream &operator<<(ostream &out, const TCubic &curve)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return out << "C{" << curve.getP0() << ", " << curve.getP1() << ", "
|
|
Toshihiro Shimizu |
890ddd |
<< curve.getP2() << ", " << curve.getP3() << "}";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ostream &operator<<(ostream &out, const TThickSegment &segment)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return out << "TS{" << segment.getThickP0() << ", " << segment.getThickP1() << "}";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ostream &operator<<(ostream &out, const TThickQuadratic &tq)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return out << "TQ{" << tq.getThickP0() << ", " << tq.getThickP1() << ", " << tq.getThickP2() << "}";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ostream &operator<<(ostream &out, const TThickCubic &tc)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return out << "TC{" << tc.getThickP0() << ", "
|
|
Toshihiro Shimizu |
890ddd |
<< tc.getThickP1() << ", "
|
|
Toshihiro Shimizu |
890ddd |
<< tc.getThickP2() << ", "
|
|
Toshihiro Shimizu |
890ddd |
<< tc.getThickP3() << "}";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
// End Of File
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|