summaryrefslogtreecommitdiff
path: root/graphics/asymptote/triple.h
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-03-04 03:02:32 +0000
committerNorbert Preining <norbert@preining.info>2020-03-04 03:02:32 +0000
commit19d25b8009801aa98ea2f46b45c37c257f990491 (patch)
treec0da70fbab26feff40e87df289ae797917df8419 /graphics/asymptote/triple.h
parentb78f5a6705512314d6fe42fd5144c5f8e5d484ce (diff)
CTAN sync 202003040302
Diffstat (limited to 'graphics/asymptote/triple.h')
-rw-r--r--graphics/asymptote/triple.h65
1 files changed, 52 insertions, 13 deletions
diff --git a/graphics/asymptote/triple.h b/graphics/asymptote/triple.h
index e0caf51192..ef65bfbef3 100644
--- a/graphics/asymptote/triple.h
+++ b/graphics/asymptote/triple.h
@@ -246,17 +246,21 @@ public:
return v.length();
}
- double polar() const /* theta */
+ double polar(bool warn=true) const /* theta */
{
double r=length();
- if (r == 0.0)
- reportError("taking polar angle of (0,0,0)");
+ if(r == 0.0) {
+ if(warn)
+ reportError("taking polar angle of (0,0,0)");
+ else
+ return 0.0;
+ }
return acos(z/r);
}
- double azimuth() const /* phi */
+ double azimuth(bool warn=true) const /* phi */
{
- return angle(x,y);
+ return angle(x,y,warn);
}
friend triple unit(const triple& v)
@@ -294,9 +298,15 @@ public:
if(paren) s >> c;
s >> z.x >> std::ws;
if(s.peek() == ',') s >> c >> z.y;
- else z.y=0.0;
+ else {
+ if(paren) s >> z.y;
+ else z.y=0.0;
+ }
if(s.peek() == ',') s >> c >> z.z;
- else z.z=0.0;
+ else {
+ if(paren) s >> z.z;
+ else z.z=0.0;
+ }
if(paren) {
s >> std::ws;
if(s.peek() == ')') s >> c;
@@ -363,14 +373,43 @@ inline double Straightness(const triple& z0, const triple& c0,
return std::max(abs2(c0-v-z0),abs2(z1-v-c1));
}
-// return the perpendicular distance squared of a point z from the plane
-// through u with unit normal n.
-inline double Distance2(const triple& z, const triple& u, const triple& n)
+// 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)
{
- double d=dot(z-u,n);
- return d*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;
+}
+
} //namespace camp
GC_DECLARE_PTRFREE(camp::triple);