Mod boundary constraint func
This commit is contained in:
parent
0b91f7bf7a
commit
dd1811a795
@ -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"
|
||||
|
@ -55,16 +55,16 @@ class SimulatorWeb extends Component {
|
||||
this.status.model.update(0);
|
||||
this.status.newLabel().name = "New Label";
|
||||
this.status.newLabel().name = "Test Label 01";
|
||||
let template = this.status.model.addBehavior(AllBehaviors[0]);
|
||||
template.name = "Template"; template.color = [150, 20, 220];
|
||||
let dynamic = this.status.model.addBehavior(AllBehaviors[1]);
|
||||
// let template = this.status.model.addBehavior(AllBehaviors[0]);
|
||||
// template.name = "Template"; template.color = [150, 20, 220];
|
||||
let dynamic = this.status.model.addBehavior(AllBehaviors[0]);
|
||||
dynamic.name = "Dynamic"; dynamic.color = [250, 200, 80];
|
||||
let brownian = this.status.model.addBehavior(AllBehaviors[2]);
|
||||
let brownian = this.status.model.addBehavior(AllBehaviors[1]);
|
||||
brownian.name = "Brownian"; brownian.color = [200, 80, 250];
|
||||
let boundary = this.status.model.addBehavior(AllBehaviors[3]);
|
||||
let boundary = this.status.model.addBehavior(AllBehaviors[2]);
|
||||
boundary.name = "Boundary"; boundary.color = [80, 200, 250];
|
||||
// boundary.parameter.range = this.status.model.allRangeLabel;
|
||||
group.addBehavior(template);
|
||||
// boundary.parameter.range.picker = this.status.model.allRangeLabel;
|
||||
// group.addBehavior(template);
|
||||
group.addBehavior(dynamic);
|
||||
group.addBehavior(brownian);
|
||||
group.addBehavior(boundary);
|
||||
|
@ -126,7 +126,7 @@ class BehaviorDetails extends Component<IBehaviorDetailsProps & IMixinStatusProp
|
||||
return <ObjectPicker
|
||||
keyI18n="Panel.Info.Behavior.Details.Parameter.Key"
|
||||
keyI18nOption={{ key: behavior.getTerms(type.name, this.props.setting?.language) }}
|
||||
type={type.type} value={(value as any).picker}
|
||||
type={type.type} value={(value as any).picker} key={indexKey}
|
||||
valueChange={(obj) => {
|
||||
(value as any).picker = obj;
|
||||
this.props.status?.changeBehaviorAttrib(behavior.id, key as string, value);
|
||||
|
Loading…
Reference in New Issue
Block a user