Published
Edited
Apr 16, 2020
Importers
Insert cell
Insert cell
Insert cell
r = 0.99999
Insert cell
data = Object.assign(
domain.map(d => ({
x: +d,
y: +next_r(r, d)
})),
{
x: "Angle (theta)",
y: "Next r"
}
)
Insert cell
next_r = (r, theta) =>
Math.sqrt(
(1 / 4) * (1 + r * (1 - 2 * Math.cos(theta))) +
r ** 2 -
r *
Math.sqrt(1 + r * (1 - 2 * Math.cos(theta))) *
Math.cos(
Math.asin(
Math.sin(theta) / Math.sqrt(1 + r * (1 - 2 * Math.cos(theta)))
)
)
)
Insert cell
points = 200
Insert cell
Insert cell
data2 = randoms.map(d => ({
x: d,
y: 2 * d
}))
Insert cell
randoms = Array(100)
.fill()
.map(d => (Math.random() * 2 - 1) * pi)
Insert cell
pi = Math.PI
Insert cell
x = d3
.scaleLinear()
.domain(d3.extent(data, d => d.x))
.nice()
.range([margin.left, width - margin.right])
Insert cell
autoScale = true
Insert cell
y = d3
.scaleLinear()
.domain(autoScale ? d3.extent(data, d => d.y) : [0, 1])
.nice()
.range([height - margin.bottom, margin.top])
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).ticks(width / 80))
.call(g => g.select(".domain").remove())
.call(g => g.append("text")
.attr("x", width)
.attr("y", margin.bottom - 4)
.attr("fill", "currentColor")
.attr("text-anchor", "end")
.text(data.x))
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.select(".domain").remove())
.call(g => g.append("text")
.attr("x", -margin.left)
.attr("y", 10)
.attr("fill", "currentColor")
.attr("text-anchor", "start")
.text(data.y))
Insert cell
grid = g => g
.attr("stroke", "currentColor")
.attr("stroke-opacity", 0.1)
.call(g => g.append("g")
.selectAll("line")
.data(x.ticks())
.join("line")
.attr("x1", d => 0.5 + x(d))
.attr("x2", d => 0.5 + x(d))
.attr("y1", margin.top)
.attr("y2", height - margin.bottom))
.call(g => g.append("g")
.selectAll("line")
.data(y.ticks())
.join("line")
.attr("y1", d => 0.5 + y(d))
.attr("y2", d => 0.5 + y(d))
.attr("x1", margin.left)
.attr("x2", width - margin.right));
Insert cell
margin = ({top: 25, right: 20, bottom: 35, left: 40})
Insert cell
height = 400
Insert cell
d3 = require("d3@5")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more