Skip to content

Commit b566876

Browse files
Fix edge sampling: DENSE sampling near cube boundaries
Now correctly samples many more points near cube edges because: - Cube edge points → Triangle edge points (where the action is!) - Dense sampling along x=0, x=1, y=0, y=1 - Extra near-edge sampling at x=0.05, x=0.95, y=0.05, y=0.95 - Multiple points near each corner - Sparse center sampling (less interesting region) Result: Much better visualization of simplex edge behavior! Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
1 parent 0e59c10 commit b566876

1 file changed

Lines changed: 78 additions & 15 deletions

File tree

docs/interactive/diffeomorphism-explorer.html

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,12 @@ <h3>🐎 Special Horse Configuration</h3>
401401
generateGrid() {
402402
const points = [];
403403

404-
// Regular grid (reduced density in center)
405-
const innerRes = Math.floor(this.resolution * 0.7);
406-
for (let i = 0; i < innerRes; i++) {
407-
for (let j = 0; j < innerRes; j++) {
408-
const x = 0.15 + (i / (innerRes - 1)) * 0.7; // Focus on [0.15, 0.85]
409-
const y = 0.15 + (j / (innerRes - 1)) * 0.7;
404+
// Sparse center grid - less density in middle of cube
405+
const centerRes = Math.floor(this.resolution * 0.4);
406+
for (let i = 0; i < centerRes; i++) {
407+
for (let j = 0; j < centerRes; j++) {
408+
const x = 0.3 + (i / (centerRes - 1)) * 0.4; // Only middle region [0.3, 0.7]
409+
const y = 0.3 + (j / (centerRes - 1)) * 0.4;
410410
const cubePoint = [x, y];
411411
const simplexPoint = this.cubeToSimplex(cubePoint);
412412
points.push({
@@ -416,10 +416,10 @@ <h3>🐎 Special Horse Configuration</h3>
416416
}
417417
}
418418

419-
// Add dense edge sampling
420-
const edgePoints = Math.floor(this.resolution * 1.5);
419+
// DENSE edge sampling - lots of points near cube boundaries
420+
const edgePoints = Math.floor(this.resolution * 2.5); // Much denser!
421421

422-
// Bottom edge (y=0)
422+
// Bottom edge (y=0) - DENSE sampling
423423
for (let i = 0; i < edgePoints; i++) {
424424
const x = i / (edgePoints - 1);
425425
const cubePoint = [x, 0];
@@ -430,7 +430,7 @@ <h3>🐎 Special Horse Configuration</h3>
430430
});
431431
}
432432

433-
// Top edge (y=1)
433+
// Top edge (y=1) - DENSE sampling
434434
for (let i = 0; i < edgePoints; i++) {
435435
const x = i / (edgePoints - 1);
436436
const cubePoint = [x, 1];
@@ -441,8 +441,8 @@ <h3>🐎 Special Horse Configuration</h3>
441441
});
442442
}
443443

444-
// Left edge (x=0)
445-
for (let i = 1; i < edgePoints - 1; i++) { // Skip corners already added
444+
// Left edge (x=0) - DENSE sampling
445+
for (let i = 1; i < edgePoints - 1; i++) {
446446
const y = i / (edgePoints - 1);
447447
const cubePoint = [0, y];
448448
const simplexPoint = this.cubeToSimplex(cubePoint);
@@ -452,8 +452,8 @@ <h3>🐎 Special Horse Configuration</h3>
452452
});
453453
}
454454

455-
// Right edge (x=1)
456-
for (let i = 1; i < edgePoints - 1; i++) { // Skip corners already added
455+
// Right edge (x=1) - DENSE sampling
456+
for (let i = 1; i < edgePoints - 1; i++) {
457457
const y = i / (edgePoints - 1);
458458
const cubePoint = [1, y];
459459
const simplexPoint = this.cubeToSimplex(cubePoint);
@@ -463,14 +463,77 @@ <h3>🐎 Special Horse Configuration</h3>
463463
});
464464
}
465465

466-
// Add corner emphasis
466+
// Extra dense near-edge regions
467+
const nearEdgePoints = Math.floor(this.resolution * 1.0);
468+
const edgeDistance = 0.05; // Very close to edges
469+
470+
// Near bottom edge (y=0.05)
471+
for (let i = 0; i < nearEdgePoints; i++) {
472+
const x = i / (nearEdgePoints - 1);
473+
const cubePoint = [x, edgeDistance];
474+
const simplexPoint = this.cubeToSimplex(cubePoint);
475+
points.push({
476+
cube: cubePoint,
477+
simplex: simplexPoint
478+
});
479+
}
480+
481+
// Near top edge (y=0.95)
482+
for (let i = 0; i < nearEdgePoints; i++) {
483+
const x = i / (nearEdgePoints - 1);
484+
const cubePoint = [x, 1 - edgeDistance];
485+
const simplexPoint = this.cubeToSimplex(cubePoint);
486+
points.push({
487+
cube: cubePoint,
488+
simplex: simplexPoint
489+
});
490+
}
491+
492+
// Near left edge (x=0.05)
493+
for (let i = 1; i < nearEdgePoints - 1; i++) {
494+
const y = i / (nearEdgePoints - 1);
495+
const cubePoint = [edgeDistance, y];
496+
const simplexPoint = this.cubeToSimplex(cubePoint);
497+
points.push({
498+
cube: cubePoint,
499+
simplex: simplexPoint
500+
});
501+
}
502+
503+
// Near right edge (x=0.95)
504+
for (let i = 1; i < nearEdgePoints - 1; i++) {
505+
const y = i / (nearEdgePoints - 1);
506+
const cubePoint = [1 - edgeDistance, y];
507+
const simplexPoint = this.cubeToSimplex(cubePoint);
508+
points.push({
509+
cube: cubePoint,
510+
simplex: simplexPoint
511+
});
512+
}
513+
514+
// Corner emphasis - multiple points near each corner
467515
const corners = [[0,0], [0,1], [1,0], [1,1]];
468516
corners.forEach(corner => {
517+
// Add the exact corner
469518
const simplexPoint = this.cubeToSimplex(corner);
470519
points.push({
471520
cube: corner,
472521
simplex: simplexPoint
473522
});
523+
524+
// Add points very close to corner
525+
for (let i = 0; i < 3; i++) {
526+
const offset = (i + 1) * 0.02;
527+
const nearCorner = [
528+
Math.max(0, Math.min(1, corner[0] + (Math.random() - 0.5) * offset)),
529+
Math.max(0, Math.min(1, corner[1] + (Math.random() - 0.5) * offset))
530+
];
531+
const nearSimplex = this.cubeToSimplex(nearCorner);
532+
points.push({
533+
cube: nearCorner,
534+
simplex: nearSimplex
535+
});
536+
}
474537
});
475538

476539
return points;

0 commit comments

Comments
 (0)