Published
Edited
Aug 30, 2021
Insert cell
Insert cell
Insert cell
Insert cell
viewof _distanceX = slider({min: 5, max: 50, step: 1, value: 3})
Insert cell
function getInterPointASegmentIntersectionCircle(center, R, pointA, pointB, _distance) {
let crossPoints = validPoints(center, R, pointA, pointB)
if (crossPoints) {
return interpolationSegment(crossPoints[0], crossPoints[1], _distance)
}
return null
}
Insert cell
function interpolationSegment (pointA, pointB, dist) {
let k = getALineK(pointA, pointB)
let resultPoint = []
if (Math.abs(k) === Infinity) {
let y1 = pointA[1];
let y2 = pointB[1];
let x = pointA[0];
let max = Math.max(y1, y2);
let min = Math.min(y1, y2);
for (let y = min; y <= max; y += dist) {
resultPoint.push([x, y]);
}
} else if (Math.abs(k) === 0) {
let x1 = pointA[0];
let x2 = pointB[0];
let y = pointA[1];
let max = Math.max(x1, x2);
let min = Math.min(x1, x2);
for (let x = min; x <= max; x += dist) {
resultPoint.push([x, y]);
}
} else {
let max, min;
if(pointA[0] < pointB[0]) {
max = pointB;
min = pointA;
} else {
max = pointA;
min = pointB;
}
let pointDis = distance(pointA, pointB);
let step = pointDis / dist;
let dx = (max[0] - min[0]) / step;
for (let i = 0; i <= step; i++) {
resultPoint.push([min[0] + i * dx, min[1] + i * dx * k]);
}
}
return resultPoint;
}
Insert cell
function getALineK(pointA, pointB) {
let x1 = pointA[0]
let y1 = pointA[1]
let x2 = pointB[0]
let y2 = pointB[1]
return (y2 - y1) / (x2 - x1)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
width = 900
Insert cell
height = 900
Insert cell
import {slider} from '@jashkenas/inputs'
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more