-
Notifications
You must be signed in to change notification settings - Fork 12
/
plotcurve.js
69 lines (65 loc) · 2 KB
/
plotcurve.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2018 Raph Levien
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
function plotFamily(curve) {
let n = 12;
let len = 36;
let minth = -Math.PI/2;
let maxth = Math.PI/2;
console.log("%!PS-Adobe-3.0")
for (var j = 0; j <= n; j++) {
let th1 = -Math.PI/2 + Math.PI * j / n;
let y = 3.5 * 72 + 6.5 * 72 * j / n;
for (var i = 0; i <= n; i++) {
let th0 = -Math.PI/2 + Math.PI * i / n;
let x = 72 + 6.5 * 72 * i / n;
let pts = curve.render(th0, th1);
console.log(`${x - 0.5 * len} ${y} moveto`);
for (var k = 0; k < pts.length; k++) {
let pt = pts[k];
console.log(`${x + (pt.x - 0.5) * len} ${y + pt.y * len}`);
if (k % 3 == 2) {
console.log("curveto");
}
}
console.log(`${x + 0.5 * len} ${y} curveto stroke`);
}
}
console.log("showpage");
}
/// Make a curvature map of a two param curve, suitable for gnuplot
function makeCurvatureMap(curve) {
let n = 50;
let mapScaling = "none";
for (var j = 0; j < n; j++) {
let th1 = -Math.PI/2 + Math.PI * j / (n - 1);
for (var i = 0; i < n; i++) {
let th0 = -Math.PI/2 + Math.PI * i / (n - 1);
let atanK = curve.computeCurvature(th0, th1).ak0;
let k = Math.tan(atanK);
let toPlot;
if (mapScaling === "none") {
toPlot = k;
} else if (mapScaling === "atan") {
toPlot = atanK;
} else if (mapScaling === "sincos2") {
// Somewhat arbitrary scaling parameter here...
let k1 = 0.25 * k;
var scaled = Math.asin((Math.sqrt(4 * k1 * k1 + 1) - 1) / (2 * k1));
if (atanK > Math.PI / 2) {
scaled = scaled + Math.PI;
} else if (atanK < -Math.PI / 2) {
scaled = scaled - Math.PI;
}
toPlot = scaled;
}
console.log(`${th0} ${th1} ${toPlot}`);
}
console.log('');
}
}
makeCurvatureMap(new BiParabola);
//plotFamily(new MyCurve);