Published
Edited
Jan 11, 2020
1 fork
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
polygon = {
let {matrix} = Flatten;

let json = await d3.json("https://gist.githubusercontent.com/alexbol99/b4fe6ac529758b0b1e981e37676d87b9/raw/f624e3a3665f8114c6b35e80cf0082c43ff08032/polygon.json")
// May try this polygon also but it has 655 edges and may work a bit slow. Check, why
// let json = await
// d3.json("https://gist.githubusercontent.com/alexbol99/af17f2f1b9dc8de9e29a60a826e0ebf2/raw/67cccc9a5739f6d4cb27bf39e6f657eb93f0150b/test_xml_0.json")
let polygon = new Flatten.Polygon(json);
return polygon
}
Insert cell
Insert cell
data = {
let {matrix,vector} = Flatten;
let box = polygon.box;
// CLone original polygon and place a copy by twice width left
let polygon1 = polygon.clone();
let polygon2 = polygon.translate( vector(-2*(box.xmax - box.xmin), 0) )
// Scale polygons to the canvase coordinate system, translate them to be in the center
let [tx, ty, k] = initial_transform([polygon1, polygon2], width,height)
let m = matrix().translate(tx,ty).scale(k,k)
polygon1 = polygon1.transform(m)
polygon2 = polygon2.transform(m)
// Rotate each polygon by angle around the center of its bounding box
let c1 = polygon1.box.center;
let c2 = polygon2.box.center;
polygon1 = polygon1.rotate(angle, c1);
polygon2 = polygon2.rotate(angle, c2);
// Calculate one-dimensional collision distance
let collision = collisionDistance(polygon2, polygon1);
// Translate polygon1 to collide with polygon2
polygon1 = polygon1.translate(vector(-collision,0));
return [polygon1, polygon2]
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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