1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-09-02 12:54:23 +02:00

added sliders to sketches that should have one, improved lazy loading

This commit is contained in:
Pomax
2020-08-21 23:39:36 -07:00
parent 65173c10a2
commit ad5da1f088
67 changed files with 833 additions and 643 deletions

View File

@@ -4,8 +4,15 @@ We can also simplify the drawing process by "sampling" the curve at certain poin
We can do this is by saying "we want X segments", and then sampling the curve at intervals that are spaced such that we end up with the number of segments we wanted. The advantage of this method is that it's fast: instead of evaluating 100 or even 1000 curve coordinates, we can sample a much lower number and still end up with a curve that sort-of-kind-of looks good enough. The disadvantage of course is that we lose the precision of working with "the real curve", so we usually can't use the flattened for for doing true intersection detection, or curvature alignment.
<graphics-element title="Flattening a quadratic curve" src="./quadratic.js"></graphics-element>
<graphics-element title="Flattening a cubic curve" src="./cubic.js"></graphics-element>
<div class="figure">
<graphics-element title="Flattening a quadratic curve" src="./quadratic.js">
<input type="range" min="1" max="16" step="1" value="4" class="slide-control">
</graphics-element>
<graphics-element title="Flattening a cubic curve" src="./cubic.js">
<input type="range" min="1" max="24" step="1" value="8" class="slide-control">
</graphics-element>
</div>
Try clicking on the sketch and using your up and down arrow keys to lower the number of segments for both the quadratic and cubic curve. You'll notice that for certain curvatures, a low number of segments works quite well, but for more complex curvatures (try this for the cubic curve), a higher number is required to capture the curvature changes properly.

View File

@@ -4,8 +4,15 @@
例えば「X個の線分がほしい」場合には、分割数がそうなるようにサンプリング間隔を選び、曲線をサンプリングします。この方法の利点は速さです。曲線の座標を100個だの1000個だの計算するのではなく、ずっと少ない回数のサンプリングでも、十分きれいに見えるような曲線を作ることができるのです。欠点はもちろん、「本物の曲線」に比べて精度が損なわれてしまうことです。したがって、交点の検出や曲線の位置揃えを正しく行いたい場合には、平坦化した曲線は普通利用できません。
<graphics-element title="2次ベジエ曲線の平坦化" src="./quadratic.js"></graphics-element>
<graphics-element title="3次ベジエ曲線の平坦化" src="./cubic.js"></graphics-element>
<div class="figure">
<graphics-element title="2次ベジエ曲線の平坦化" src="./quadratic.js">
<input type="range" min="1" max="16" step="1" value="4" class="slide-control">
</graphics-element>
<graphics-element title="3次ベジエ曲線の平坦化" src="./cubic.js">
<input type="range" min="1" max="24" step="1" value="8" class="slide-control">
</graphics-element>
</div>
2次ベジエ曲線も3次ベジエ曲線も、図をクリックして上下キーを押すと曲線の分割数が増減しますので、試してみてください。ある曲線では分割数が少なくてもうまくいきますが、曲線が複雑になればなるほど、曲率の変化を正確に捉えるためにはより多くの分割数が必要になることがわかります3次ベジエ曲線で試してみてください

View File

@@ -4,8 +4,15 @@
我们可以先确定“想要X个分段”然后在间隔的地方采样曲线得到一定数量的分段。这种方法的优点是速度很快比起遍历100甚至1000个曲线坐标我们可以采样比较少的点仍然得到看起来足够好的曲线。这么做的缺点是我们失去了“真正的曲线”的精度因此不能用此方法来做真实的相交检测或曲率对齐。
<graphics-element title="拉平一条二次曲线" src="./quadratic.js"></graphics-element>
<graphics-element title="拉平一条次曲线" src="./cubic.js"></graphics-element>
<div class="figure">
<graphics-element title="拉平一条次曲线" src="./quadratic.js">
<input type="range" min="1" max="16" step="1" value="4" class="slide-control">
</graphics-element>
<graphics-element title="拉平一条三次曲线" src="./cubic.js">
<input type="range" min="1" max="24" step="1" value="8" class="slide-control">
</graphics-element>
</div>
试着点击图形,并用上下键来降低二次曲线和三次曲线的分段数量。你会发现对某些曲率来说,数量少的分段也能做的很好,但对于复杂的曲率(在三次曲线上试试),足够多的分段才能很好地满足曲率的变化。

View File

@@ -2,6 +2,11 @@ setup() {
this.steps = 8;
this.curve = Bezier.defaultCubic(this);
setMovable(this.curve.points);
setSlider(`.slide-control`, v => this.setStep(v));
}
setStep(v) {
this.steps = v;
}
draw() {
@@ -23,23 +28,6 @@ draw() {
text(`Flattened to ${this.steps} segments`, 10, 15);
}
onKeyDown() {
let key = this.keyboard.currentKey;
if(key === `ArrowUp`) {
this.steps++;
}
if(key === `ArrowDown`) {
if(this.steps > 1) this.steps--;
}
redraw();
}
onMouseMove() {
if (this.cursor.down && !this.currentPoint) {
this.steps = round( map(this.cursor.y, 0,this.height, 24, 1) );
}
redraw();
}

View File

@@ -2,6 +2,11 @@ setup() {
this.steps = 4;
this.curve = Bezier.defaultQuadratic(this);
setMovable(this.curve.points);
setSlider(`.slide-control`, v => this.setStep(v));
}
setStep(v) {
this.steps = v;
}
draw() {
@@ -23,23 +28,6 @@ draw() {
text(`Flattened to ${this.steps} segments`, 10, 15);
}
onKeyDown() {
let key = this.keyboard.currentKey;
if(key === `ArrowUp`) {
this.steps++;
}
if(key === `ArrowDown`) {
if(this.steps > 1) this.steps--;
}
redraw();
}
onMouseMove() {
if (this.cursor.down && !this.currentPoint) {
this.steps = round( map(this.cursor.y, 0,this.height, 16, 1) );
}
redraw();
}