|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
import { useEffect, useRef, useState } from 'preact/hooks'
|
|
|
|
|
import { resampleCurve, simplifyCurve } from '../../lib/math/curves.js'
|
|
|
|
|
import { clamp, Vec2 } from '../../lib/math/math.js'
|
|
|
|
|
import { Vec2 } from '../../lib/math/math.js'
|
|
|
|
|
|
|
|
|
|
function createSimulation(positions, velocities, accelerations) {
|
|
|
|
|
function createSimulation2d(positions, velocities, accelerations) {
|
|
|
|
|
return {
|
|
|
|
|
positions,
|
|
|
|
|
velocities,
|
|
|
|
@ -14,10 +14,8 @@ function createSimulation(positions, velocities, accelerations) {
|
|
|
|
|
const newVelocities = Array.from({ length: n }, () => [])
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
|
newPositions[i][0] = this.positions[i][0] + this.velocities[i][0] + this.accelerations[i][0] * 0.5
|
|
|
|
|
newPositions[i][1] = this.positions[i][1] + this.velocities[i][1] + this.accelerations[i][1] * 0.5
|
|
|
|
|
newVelocities[i][0] = this.velocities[i][0] + (this.accelerations[i][0] + newAccelerations[i][0]) * 0.5
|
|
|
|
|
newVelocities[i][1] = this.velocities[i][1] + (this.accelerations[i][1] + newAccelerations[i][1]) * 0.5
|
|
|
|
|
newPositions[i] = Vec2.add(Vec2.add(this.positions[i], this.velocities[i]), Vec2.scale(this.accelerations[i], 0.5))
|
|
|
|
|
newVelocities[i] = Vec2.add(this.velocities[i], Vec2.scale(Vec2.add(this.accelerations[i], newAccelerations[i]), 0.5))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.positions = newPositions
|
|
|
|
@ -76,7 +74,7 @@ class KnotSimulation {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setPositions(positions) {
|
|
|
|
|
this.particleSimulation = createSimulation(
|
|
|
|
|
this.particleSimulation = createSimulation2d(
|
|
|
|
|
positions,
|
|
|
|
|
Array.from({ length: positions.length }, () => [0, 0]),
|
|
|
|
|
Array.from({ length: positions.length }, () => [0, 0])
|
|
|
|
|