-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
Sources/ForceSimulation/ForceSimulation.docc/Creating2DAnd3DSimulations.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Creating 2D and 3D simulations | ||
|
||
|
||
## Overview | ||
|
||
You can simply create 2D or 3D simulations by using Simulation2D or Simulation3D: | ||
|
||
```swift | ||
import NDTree | ||
import ForceSimulation | ||
|
||
struct Node: Identifiable { ... } | ||
|
||
let nodeIds: [Node.ID] = ... | ||
let links: [(Node.ID, Node.ID)] = ... | ||
|
||
let sim = Simulation2D(nodeIds: nodeIds, alphaDecay: 0.01) | ||
sim.createManyBodyForce(strength: -12) | ||
sim.createLinkForce(links) | ||
sim.createCenterForce(center: [0, 0], strength: 0.4) | ||
sim.createCollideForce(radius: .constant(3)) | ||
|
||
/// Force is ready to start! run `tick` to iterate the simulation. | ||
|
||
for i in 0..<120 { | ||
sim.tick() | ||
let positions = sim.nodePositions | ||
/// Do something with the positions. | ||
} | ||
|
||
``` | ||
|
||
See [Example](https://github.com/li3zhen1/Grape/tree/main/Examples/ForceDirectedGraphExample) for more details. |
34 changes: 34 additions & 0 deletions
34
Sources/ForceSimulation/ForceSimulation.docc/Documentation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# ``ForceSimulation`` | ||
|
||
Run force simulation on any dimension. | ||
|
||
## Overview | ||
|
||
ForceSimulation is a force simulation library that enables you to create any dimensional simulation with velocity Verlet integration. | ||
|
||
The basic concepts of simulations and forces can be found here: [Force simulations - D3](https://d3js.org/d3-force/simulation). | ||
|
||
|
||
@Image(source: "ForceDirectedGraph.png", alt: "An example of 2D force directied graph.") | ||
|
||
|
||
|
||
## Topics | ||
|
||
|
||
### Creating a simulation | ||
|
||
* <doc:Creating2DAnd3DSimulations> | ||
* ``Simulation2D`` | ||
* ``Simulation3D`` | ||
|
||
* ``Simulation`` | ||
|
||
### Creating forces in a simulation | ||
* ``CenterForce`` | ||
* ``CollideForce`` | ||
* ``LinkForce`` | ||
* ``ManyBodyForce`` | ||
* ``DirectionForce`` | ||
* ``RadialForce`` | ||
* ``ForceLike`` |
Binary file added
BIN
+424 KB
Sources/ForceSimulation/ForceSimulation.docc/Resources/ForceDirectedGraph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters