What is the meaning of group.nodeLocation in One simulator syntax? - simulation

I was reading some tutorial of One simulator. I got one syntax that is
group.nodeLocation = 100,100
As far as I know a group can have multiple nodes. Therefore, I am not clear what does it mean by group.nodeLocation. Which node location we are fixing by using this command.
Thanks,

It depends on which kind of movement models you use.
Setting group.nodeLocation is required for StationaryMovement, but for other dynamic movement modes (e.g., RandomWaypoint) is meaningless.
If you want to set multiple nodes N with different location, you should separate it into N groups.
In speaking of adding static nodes in bulk, use MapRouterMovement to simulate it. The static node can be regarded as the initioal coordination equals the destination coordination. For instance, 5 static nodes are defined as:
LINESTRING (100 100, 100.0 100.0)
LINESTRING (200 200, 200.0 200.0)
LINESTRING (300 300, 300.0 300.0)
LINESTRING (400 400, 400.0 400.0)
LINESTRING (500 500, 500.0 500.0)
And the setting file like:
Group4.groupID = b
Group4.movementModel = MapRouteMovement #MapRouteMovement
Group4.routeFile = path/routFile.wkt #routeFile
Group4.routeType = 2
Group4.nrofHosts = 5
Group4.waitTime = 0, 0
Group4.speed = 0, 0
BTW, don't forget to group the above coordinations as a map file, seeing below:
#settings.txt
MapBasedMovement.nrofMapFiles = 1
MapBasedMovement.mapFile1 = path/mapFile.wkt
#mapFile.wkt
LINESTRING (100 100, 200.0 200.0, 300 300, 400 400, 500.0 500.0)

Related

In scene kit, SCNPhysicsField.noiseField seems to just terminate, end, after a few seconds

Have an SCNNode, add a physics body,
physicsBody = SCNPhysicsBody(type: .dynamic, shape: ..)
physicsBody?.isAffectedByGravity = false
Now add a physics field, for example
physicsField = SCNPhysicsField.noiseField(smoothness: 0.2, animationSpeed: 0.01)
physicsField?.strength = 0.05
It works perfectly. In this case, .noise , the object will jiggle around.
However after a few seconds (often 7 seconds, sometimes a different length of time), the object will simply stop moving.
(The three values, smoothness speed and strength, make no difference if you change them - it will still end after a few seconds.)
What's the solution to this mystery?
Just to be clear, I never used a SCNPhysicsField.noiseField, but I used one of type SCNPhysicsField.linearGravity and another of type SCNPhysicsField.customField and both of them are working correctly and do not stop unexpected as you describe.
here are my examples:
let attractionField = SCNPhysicsField.linearGravity()
attractionField.halfExtent = SCNVector3(250.0, 35.0, 60.0)
attractionField.direction = SCNVector3(-1.0, 0.0, 0.0)
attractionField.strength = 0.2 // 0.15
attractionNode.physicsField = attractionField
and the other one, (which I used to create a tornado):
private func addCustomVortexField() {
// Tornado Particles Field
let worldOrigin = stormNode.presentation.worldPosition
let worldAxis = simd_float3(0.0, 1.0, 0.0)
let customVortexField = SCNPhysicsField.customField(evaluationBlock: { position, velocity, mass, charge, time in
let l = simd_float3(worldOrigin.x - position.x, 1.0, worldOrigin.z - position.z)
let t = simd_cross(worldAxis, l)
let d2: Float = l.x * l.x + l.z * l.z
let vs: Float = 27 / sqrt(d2) // diameter, the bigger the value the wider it becomes
let fy: Float = 1.0 - Float((min(1.0, (position.y / 240.0)))) // rotations, a higher value means more turn arounds (more screwed)
return SCNVector3Make(t.x * vs + l.x * 10 * fy, 0, t.z * vs + l.z * 10 * fy)
})
customVortexField.halfExtent = SCNVector3Make(100, 100, 100)
stormNode.physicsField = customVortexField
stormNode.physicsField?.categoryBitMask = BitMasks.BitmaskTornadoField
}
I hope this is gonna help you in some way. You can also provide me your project, and I will have a look at it.

First time using cairo in AwesomeWM

This is for anyone who's having trouble getting started with cairo.
The documentation didn't give a good, complete example. That's why I wanted to share this.
I created a concrete example which you can put in your rc.lua and play with it.
local wibox = require('wibox')
local cairo = require("lgi").cairo
local surface = cairo.ImageSurface(cairo.Format.RGB24,20,20)
local cr = cairo.Context(surface)
my_wbox = wibox()
my_wbox.visible = true
my_wbox:set_bg("#ff0000")
cairo_widget = wibox.widget.base.make_widget()
cairo_widget.fit = function(context, width, height)
return 100, 100
end
cairo_widget.draw = function(self, my_wbox, cr, width, height)
cr:translate(100, 100)
cr:set_source_rgb(0,0,0)
cr:rectangle(0, 0, 100, 100)
cr:fill()
end
my_wbox:set_widget(cairo_widget)
my_wbox:geometry({x=50, y=50, width=500, height=500})
There is https://awesomewm.org/apidoc/documentation/04-new-widgets.md.html, but I guess that page does not have a "here is everything in one copy-able chunk" at the end.

How in Flink CEP can we detect a pattern that last a period of time?

I want to detect a pattern with Flink CEP, here my use case:
I should raise an event when i got the speed of my vehicle above a speedLimit for a laps of time.
Example1: (speedlimit = 100, period=60 seconds)
event1: speed = 50, eventtime=0
event1: speed = 100, eventtime=10
event1: speed = 120, eventtime=30
event1: speed = 150, eventtime=40
event1: speed = 120, eventtime=70
event1: speed = 50, eventtime=90
=> raise 1 event
Example1: (speedlimit = 100, period=60 seconds)
event1: speed = 50, eventtime=0
event1: speed = 100, eventtime=10
event1: speed = 120, eventtime=30
event1: speed = 150, eventtime=40
event1: speed = 60, eventtime=70
=> raise 0 event
Please, your help.
I would approach this by looking for a sequence of 2 or more events where the speed is greater than or equal to 100 for all of them, and where the timestamp of the last one minus the timestamp of the first one is greater than or equal to 60.
By the way, you may find MATCH_RECOGNIZE is easier to work with, but either it or CEP should be fine for this use case.

How to use SceneKit vortex field to create a tornato effect

In the SceneKit WWDC 2014, they have an example of a vortex field with this effect:
The particle system looks much like a tornato, as it spins inward with a hollow center.
However, the documentation for vortex fields have no information on how to achieve this effect. Right now, I have this:
// create the particle system
let exp = SCNParticleSystem()
exp.loops = true
exp.particleMass = 5
exp.birthRate = 10000
exp.emissionDuration = 10
exp.emitterShape = SCNTorus(ringRadius: 5, pipeRadius: 1)
exp.particleLifeSpan = 15
exp.particleVelocity = 2
exp.particleColor = UIColor.white
exp.isAffectedByPhysicsFields = true
scene.addParticleSystem(exp, transform: SCNMatrix4MakeRotation(0, 0, 0, 0))
// create the field
let field = SCNPhysicsField.vortex()
field.strength = -5
field.direction = SCNVector3(x: 0, y: 1, z: 0)
let fieldNode = SCNNode()
fieldNode.physicsField = field
scene.rootNode.addChildNode(fieldNode)
This creates this effect:
Where I am looking down at the particles rotating clockwise with a really big radius outwards. It looks nothing like a tornato effect. How can I create this effect?
You say tornato, I say tornado, let’s call the whole thing off...
The SceneKit WWDC 2014 demo/slides is a sample code project, so you can see for yourself how they made any of the effects you see therein. In this case, it looks like the “vortex” demo isn’t actually using the vortexField API, but instead the custom field API that lets you supply your own math in an evaluator block. (See the link for the code in that block.)
You might be able to get similar behavior without a custom field by combining a vortex (causes rotation only) with radial gravity (attracts inward) with linear gravity (attracts downward), or some other combination (possibly something involving electric charge). But you’d probably have to experiment with tweaking the parameters quite a bit.
If anyone is still interested in this topic - here is a Swift 5 implementation of that legendary tornado effect.
Here is an example function that will create your tornado.
func addTornadoPhysicsField() {
// Tornado Particles Field Example
guard let tornadoSystem = SCNParticleSystem(named: "tornado.scnp", inDirectory: nil) else { return }
let emitterGeometry = SCNTorus(ringRadius: 1.0, pipeRadius: 0.2)
emitterGeometry.firstMaterial?.transparency = 0.0
let fieldAndParticleNode = SCNNode(geometry: emitterGeometry)
fieldAndParticleNode.position = SCNVector3(0.0, 0.0, -20.0)
tornadoSystem.emitterShape = emitterGeometry
fieldAndParticleNode.addParticleSystem(tornadoSystem)
yourScene.rootNode.addChildNode(fieldAndParticleNode)
// Tornado
let worldOrigin = SCNVector3Make(fieldAndParticleNode.worldTransform.m41,
fieldAndParticleNode.worldTransform.m42,
fieldAndParticleNode.worldTransform.m43)
let worldAxis = simd_float3(0.0, 1.0, 0.0) // i.Ex. the Y axis
// Custom Field (Tornado)
let customVortexField = SCNPhysicsField.customField(evaluationBlock: { position, velocity, mass, charge, time in
let l = simd_float3(worldOrigin.x - position.x, 1.0, worldOrigin.z - position.z)
let t = simd_cross(worldAxis, l)
let d2: Float = l.x * l.x + l.z * l.z
let vs: Float = 27 / sqrt(d2) // diameter, the bigger the value the wider it becomes (Apple Default = 20)
let fy: Float = 1.0 - Float((min(1.0, (position.y / 240.0)))) // rotations, a higher value means more turn arounds (more screwed, Apple Default = 15.0))
return SCNVector3Make(t.x * vs + l.x * 10 * fy, 0, t.z * vs + l.z * 10 * fy)
})
customVortexField.halfExtent = SCNVector3Make(100, 100, 100)
fieldAndParticleNode.physicsField = customVortexField // Attach the Field
}
Additional Configuration Options:
Finally all this can result in something like that:
Note: if you would like to move your static tornado almost like a real tornado, you will have to find a way to re-apply the physics field for each rendererd frame. If you don't, the world origin used in the evaluation block will not move and it will distort your tornado.
Note: You can also split the particle/field node into two different nodes that moves independently from each other. Constrain the field node to the position of the particle node and play around with the influence factor (still need to re-apply the field each frame)
For more information on Custom Fields check out here.

How to get an SKAction.sequence to wait for a random duration

I'm trying to get a door to open up, wait for a random amount of time (within a range) and then close. If I use SKAction.waitForDuration, I can set the exact time to wait, and that works. However, if I use SKAction.waitForDuration (withRange), it always opens exactly at the shortest time in the range. How to I get it to open at other times within the range? Any help would be greatly appreciated! Thanks!
Here's my code:
var doorAction = SKAction.moveTo(CGPoint(x: size.width * 0.5, y: size.height + size.height * 1.95), duration: NSTimeInterval(1))
// randomWait should give me a value between 10 & 30, but door always opens at 10
var randomWait = SKAction.waitForDuration(20.0, withRange: 20.0)
// waitAction works fine, but I want a value between 10 and 30
// var waitAction = SKAction.waitForDuration(10)
var doorReturnAction = SKAction.moveTo(CGPoint(x: size.width * 0.5, y: size.height * 2.18), duration: NSTimeInterval(1))
var actionSequence = SKAction.sequence([doorAction, randomWait, doorReturnAction])
self.runAction(actionSequence)
Since you are not repeating the action sequence you don't really need SKAction.waitForDuration:withRange:. You can calculate a waitDuration using arc4random()
let upperlimit : UInt32 = 30
let lowerlimit : UInt32 = 10
let waitDuration = NSTimeInterval(CGFloat(arc4random() % ((upperlimit - lowerlimit) * 10) + lowerlimit * 10)/10.0)
var randomWait = SKAction.waitForDuration(waitDuration)
From the docs.
sec - The average amount of time to wait.
durationRange - The range of possible values for the duration.
If you set 20 to be the average, and the range only goes up to 20 then the only way it can meet that is to always open at 20. You should try having the first parameter (the average) be somewhere close to the middle of the range, if you want the behavior to be less uniform.