В реализации есть две проблемы:
- Везде, где есть асимптота, всегда есть связь. Как я могу автоматически обнаружить асимптоты на графике и убедиться, что они не связаны?
- По какой-то причине график не имитирует истинный график tan( х) или 1/x. Точки разрыва не отображаются должным образом.
Код: Выделить всё
let smooth = 0.1;
let container = document.getElementById("svg");
let width = container.getAttribute("width");
let height = container.getAttribute("height");
let xmin = -5 * 2 * Math.PI;
let xmax = 5 * 2 * Math.PI;
let ymin = -10;
let ymax = 10;
function f(x) { //use tan(x) or 1 / x
return Math.tan(x);
//return 1 / x;
}
let points = generatePoints(xmin, xmax, 150);
let thePath = document.getElementById("thePath");
thePath.setAttribute("d", drawCurve(points));
thePath.setAttribute("stroke-width", 2);
thePath.setAttribute("opacity", 1);
thePath.setAttribute("stroke-linecap", "circle");
thePath.setAttribute("stroke-linejoin", "miter");
thePath.setAttribute("shape-rendering", "auto");
points.forEach((point) => { // magenta points
plotSinglePoint(point.x, point.y);
});
////////////////////////////////////////////////////////////////////////////////
// Implementation below //
////////////////////////////////////////////////////////////////////////////////
function generatePoints(xMin, xMax, samples = 50) {
result = [];
let xInc = (xMax - xMin) / samples;
for (let x = xMin; x < xMax; x += xInc) {
let xVal = coordX(x);
let yVal = coordY(f(x));
let point = { x: xVal, y: yVal };
if (isValidPoint(point)) {
result.push(point);
}
}
result.forEach((p) => {
if (p.x == NaN || p.y == NaN) {
console.log(p);
}
});
return result;
}
function isValidPoint(point) {
return 0
Подробнее здесь: [url]https://stackoverflow.com/questions/79336155/javascript-plotting-functions-with-asymptotes[/url]