return triple((t[0]*v.x+t[1]*v.y+t[2]*v.z+t[3])*f,
(t[4]*v.x+t[5]*v.y+t[6]*v.z+t[7])*f,
(t[8]*v.x+t[9]*v.y+t[10]*v.z+t[11])*f);
}
reportError("division by 0 in transform of a triple");
return 0.0;
}
// Returns a unit triple in the direction (theta,phi), in radians.
friend triple expi(double theta, double phi)
{
double sintheta=sin(theta);
return triple(sintheta*cos(phi),sintheta*sin(phi),cos(theta));
}
friend istream& operator >> (istream& s, triple& z)
{
char c;
s >> ws;
bool paren=s.peek() == '('; // parenthesis are optional
if(paren) s >> c;
s >> z.x >> ws;
if(s.peek() == ',') s >> c >> z.y >> ws;
else {
if(paren) s >> z.y >> ws;
else z.y=0.0;
}
if(s.peek() == ',') s >> c >> z.z;
else {
if(paren) s >> z.z;
else z.z=0.0;
}
if(paren) {
s >> ws;
if(s.peek() == ')') s >> c;
}
// return the maximum distance squared of points c0 and c1 from
// the respective internal control points of z0--z1.
inline double Straightness(const triple& z0, const triple& c0,
const triple& c1, const triple& z1)
{
triple v=third*(z1-z0);
return std::max(abs2(c0-v-z0),abs2(z1-v-c1));
}
// Return one ninth of the relative flatness squared of a--b and c--d.
inline double Flatness(const triple& a, const triple& b, const triple& c,
const triple& d)
{
static double ninth=1.0/9.0;
triple u=b-a;
triple v=d-c;
return ninth*std::max(abs2(cross(u,unit(v))),abs2(cross(v,unit(u))));
}
// Return one-half of the second derivative of the Bezier curve defined by
// a,b,c,d at t=0.
inline triple bezierPP(const triple& a, const triple& b, const triple& c) {
return 3.0*(a+c)-6.0*b;
}
// Return one-sixth of the third derivative of the Bezier curve defined by
// a,b,c,d at t=0.
inline triple bezierPPP(const triple& a, const triple& b, const triple& c,
const triple& d) {
return d-a+3.0*(b-c);
}
// Return four-thirds of the first derivative of the Bezier curve defined by
// a,b,c,d at t=1/2.
inline triple bezierPh(triple a, triple b, triple c, triple d)
{
return c+d-a-b;
}
// Return two-thirds of the second derivative of the Bezier curve defined by
// a,b,c,d at t=1/2.
inline triple bezierPPh(triple a, triple b, triple c, triple d)
{
return 3.0*a-5.0*b+c+d;
}