Published
Edited
Apr 5, 2022
1 star
Insert cell
Insert cell
desenho = html`<svg width=600 height=400 style="border:1px solid gray" >`
Insert cell
Insert cell
S1 = ({
u0 : [60, 0, 0],
u1 : [15, 40, 0],
o : [40,100, 1]
})
Insert cell
Insert cell
M1 = [...S1.u0, ...S1.u1, ...S1.o]
Insert cell
Insert cell
M1Inv = mat3.invert([], M1)
Insert cell
Insert cell
mutable P = [100,200,1]
Insert cell
Insert cell
P_S1 = vec3.transformMat3([],P,M1Inv)
Insert cell
Insert cell
// Função para retornar a especificação de path (atributo d) de uma seta de p para q
function arrow (p,q) {
const u = vec2.scale([], vec2.normalize([], vec2.sub([], q, p)), 8);
const q1 = vec2.add ([], q, vec2.rotate([], u, [0,0], Math.PI*0.8));
const q2 = vec2.add ([], q, vec2.rotate([], u, [0,0], -Math.PI*0.8));
return `M ${p[0]},${p[1]} L${q[0]},${q[1]} m0,0 L${q1[0]},${q1[1]} L${q2[0]},${q2[1]} Z`
}
Insert cell
{
desenho.innerHTML = `
<path d="${arrow(S1.o, vec2.add([],S1.o, S1.u0))}" stroke=black />
<path d="${arrow(S1.o, vec2.add([],S1.o, S1.u1))}" stroke=black />
<circle cx=${S1.o[0]} cy=${S1.o[1]} r=5 />
<circle cx=${P[0]} cy=${P[1]} r=5 fill=blue />`;
for (let ix = 0; ix < 8; ix++) {
for (let iy = 0; iy < 8; iy++) {
let q = vec2.add([], S1.o,
vec2.add ([],
vec2.scale ([], S1.u0, ix),
vec2.scale ([], S1.u1, iy)));
desenho.append(svg`<circle cx=${q[0]} cy=${q[1]} r=1.5 fill=red >`)
}
}
let [x,y] = P_S1.map( _ => _.toFixed(2));
desenho.append (svg`<text x=${P[0]} y=${P[1]} dx=10 >(${x}, ${y})</text>` )
desenho.onclick = (e) => {
mutable P = [e.offsetX, e.offsetY, 1]
}
}
Insert cell
Insert cell
import {vec2, vec3, mat3 } from "@esperanc/vec2-utils"
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