From dd1811a79583f40cbce80f30baf2c2fbd351af91 Mon Sep 17 00:00:00 2001 From: MrKBear Date: Tue, 5 Apr 2022 23:00:13 +0800 Subject: [PATCH] Mod boundary constraint func --- source/Behavior/Behavior.ts | 2 +- source/Behavior/BoundaryConstraint.ts | 53 ++++++++++++++++--- source/Behavior/Dynamics.ts | 6 ++- source/Page/SimulatorWeb/SimulatorWeb.tsx | 14 ++--- .../Panel/BehaviorDetails/BehaviorDetails.tsx | 2 +- 5 files changed, 60 insertions(+), 17 deletions(-) diff --git a/source/Behavior/Behavior.ts b/source/Behavior/Behavior.ts index 15c2dad..6fc5c89 100644 --- a/source/Behavior/Behavior.ts +++ b/source/Behavior/Behavior.ts @@ -5,7 +5,7 @@ import { Brownian } from "./Brownian"; import { BoundaryConstraint } from "./BoundaryConstraint"; const AllBehaviors: IAnyBehaviorRecorder[] = [ - new BehaviorRecorder(Template), + // new BehaviorRecorder(Template), new BehaviorRecorder(Dynamics), new BehaviorRecorder(Brownian), new BehaviorRecorder(BoundaryConstraint), diff --git a/source/Behavior/BoundaryConstraint.ts b/source/Behavior/BoundaryConstraint.ts index bf1cb59..32c7c71 100644 --- a/source/Behavior/BoundaryConstraint.ts +++ b/source/Behavior/BoundaryConstraint.ts @@ -1,12 +1,12 @@ import { Behavior } from "@Model/Behavior"; import { Group } from "@Model/Group"; import { Individual } from "@Model/Individual"; -import { Label } from "@Model/Label"; import { Model } from "@Model/Model"; import { Range } from "@Model/Range"; type IBoundaryConstraintBehaviorParameter = { - range: "LR" + range: "LR", + strength: "number" } type IBoundaryConstraintBehaviorEvent = {} @@ -27,6 +27,13 @@ class BoundaryConstraint extends Behavior rangeList[i].radius[1]; let oz = Math.abs(rz) > rangeList[i].radius[2]; - individual.applyForce( - ox ? rx : 0, - oy ? ry : 0, - oz ? rz : 0 - ) + if (ox || oy || oz) { + + let currentFLen = individual.vectorLength(rx, ry, rz); + if (currentFLen < fLen) { + fx = rx; + fy = ry; + fz = rz; + fLen = currentFLen; + } + + } else { + + fx = 0; + fy = 0; + fz = 0; + fLen = 0; + } } + + individual.applyForce( + fx * this.parameter.strength, + fy * this.parameter.strength, + fz * this.parameter.strength + ); } } diff --git a/source/Behavior/Dynamics.ts b/source/Behavior/Dynamics.ts index cb8c8fb..d41ef84 100644 --- a/source/Behavior/Dynamics.ts +++ b/source/Behavior/Dynamics.ts @@ -49,7 +49,7 @@ class Dynamics extends Behavior { (value as any).picker = obj; this.props.status?.changeBehaviorAttrib(behavior.id, key as string, value);