Mod boundary constraint func
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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<IBoundaryConstraintBehaviorParameter,
|
||||
range: {
|
||||
type: "LR",
|
||||
name: "$range"
|
||||
},
|
||||
strength: {
|
||||
type: "number",
|
||||
name: "$Strength",
|
||||
defaultValue: 1,
|
||||
numberMin: 0,
|
||||
numberStep: .1
|
||||
}
|
||||
};
|
||||
|
||||
@@ -35,6 +42,14 @@ class BoundaryConstraint extends Behavior<IBoundaryConstraintBehaviorParameter,
|
||||
"ZH_CN": "边界约束",
|
||||
"EN_US": "Boundary constraint"
|
||||
},
|
||||
"$range": {
|
||||
"ZH_CN": "约束范围",
|
||||
"EN_US": "Constraint range"
|
||||
},
|
||||
"$Strength": {
|
||||
"ZH_CN": "约束强度系数",
|
||||
"EN_US": "Restraint strength coefficient"
|
||||
},
|
||||
"$Intro": {
|
||||
"ZH_CN": "个体越出边界后将主动返回",
|
||||
"EN_US": "Individuals will return actively after crossing the border"
|
||||
@@ -43,6 +58,12 @@ class BoundaryConstraint extends Behavior<IBoundaryConstraintBehaviorParameter,
|
||||
|
||||
public effect(individual: Individual, group: Group, model: Model, t: number): void {
|
||||
let rangeList: Range[] = this.parameter.range.objects;
|
||||
|
||||
let fx = 0;
|
||||
let fy = 0;
|
||||
let fz = 0;
|
||||
let fLen = Infinity;
|
||||
|
||||
for (let i = 0; i < rangeList.length; i++) {
|
||||
|
||||
let rx = rangeList[i].position[0] - individual.position[0];
|
||||
@@ -53,12 +74,30 @@ class BoundaryConstraint extends Behavior<IBoundaryConstraintBehaviorParameter,
|
||||
let oy = Math.abs(ry) > 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ class Dynamics extends Behavior<IDynamicsBehaviorParameter, IDynamicsBehaviorEve
|
||||
resistance: {
|
||||
name: "$Resistance",
|
||||
type: "number",
|
||||
defaultValue: 0.1,
|
||||
defaultValue: 0.5,
|
||||
numberStep: .1,
|
||||
numberMin: 0
|
||||
}
|
||||
@@ -76,6 +76,10 @@ class Dynamics extends Behavior<IDynamicsBehaviorParameter, IDynamicsBehaviorEve
|
||||
"ZH_CN": "最大速度 (m/s)",
|
||||
"EN_US": "Maximum velocity (m/s)"
|
||||
},
|
||||
"$Resistance": {
|
||||
"ZH_CN": "阻力系数",
|
||||
"EN_US": "Resistance coefficient"
|
||||
},
|
||||
"$Physics": {
|
||||
"ZH_CN": "物理",
|
||||
"EN_US": "Physics"
|
||||
|
||||
Reference in New Issue
Block a user