vasturiano / d3-force-surface Goto Github PK
View Code? Open in Web Editor NEWA multi-surface elastic collision force type for the d3-force simulation engine
License: MIT License
A multi-surface elastic collision force type for the d3-force simulation engine
License: MIT License
Following the example from the readme, I've specified a bounding box for my simulation as follows:
const [ x1, x2, y1, y2 ] = [ -width/2, width/2, -height/2, height/2 ]
this.simulation.force('bounding-box',
forceSurface().surfaces([
{from:{x:x1,y:y1},to:{x:x2,y:y1}}, // top
{from:{x:x1,y:y2},to:{x:x2,y:y2}}, // bottom
{from:{x:x1,y:y1},to:{x:x1,y:y2}}, // left
{from:{x:x2,y:y1},to:{x:x2,y:y2}} // right
]).radius(n=>n.radius).elasticity(0)
)
This works great (Yay!) but it also strikes me as very verbose and hard to read. In the geospatial world, we often specify bounding boxes as [[x1,y1],[x2,y2]]
(i.e. [top-left],[bottom-right]).
Or alternatively an arbitrary polyline could be specified as a series of sequential points given as [x,y]
coordinates. Thus my bounding box would be [[x1,y1],[x2,y1],[x2,y2],[x1,y2],[x1,y1]]
with five points defining four surfaces.
It would be nice if these more succinct formats could be parsed as well. This could even allow some direct interactions with e.g. d3-geo, though I have a feeling this force would scale badly for complex (multi)polygons. Still, there might be some really interesting use cases there.
Anyway, just a friendly suggestion. This library is exactly what I was looking for - thanks for your work on this!
Hello,
Thank You for this nice surface collision force algorithm. Is there a way to specify the width and height of a node instead of only the radius?
That would be really cool!
Best,
Jan
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.