I want to find out, what is the maximum speed that I can be walking and be able to brake by reaching displacement 0 with speed 0.
I need an equation that works with discrete time.
How am I updating and moving the body?
First, the speed is updated
Second, the position is updated: NewPosition = LastPosition + Velocity
Thus, for example, a table of expected results follows:
MaxStoppableVelocity ( Displacement = 0m, Deceleration = -2m/s² ) should be 2m/s
MaxStoppableVelocity ( Displacement = 1m, Deceleration = -2m/s² ) should be 3m/s
MaxStoppableVelocity ( Displacement = 2m, Deceleration = -2m/s² ) should be 4m/s
MaxStoppableVelocity ( Displacement = 3m, Deceleration = -2m/s² ) should be 4.5m/s
MaxStoppableVelocity ( Displacement = 4m, Deceleration = -2m/s² ) should be 5m/s
MaxStoppableVelocity ( Displacement = 5m, Deceleration = -2m/s² ) should be 5.5m/s
MaxStoppableVelocity ( Displacement = 6m, Deceleration = -2m/s² ) should be 6m/s
MaxStoppableVelocity ( Displacement = 7m, Deceleration = -2m/s² ) should be 6.33m/s
MaxStoppableVelocity ( Displacement = 8m, Deceleration = -2m/s² ) should be 6.66m/s
MaxStoppableVelocity ( Displacement = 9m, Deceleration = -2m/s² ) should be 7m/s
MaxStoppableVelocity ( Displacement = 10m, Deceleration = -2m/s² ) should be 7.33m/s
MaxStoppableVelocity ( Displacement = 11m, Deceleration = -2m/s² ) should be 7.66m/s
MaxStoppableVelocity ( Displacement = 12m, Deceleration = -2m/s² ) should be 8m/s
MaxStoppableVelocity ( Displacement = 13m, Deceleration = -2m/s² ) should be 8.25m/s
MaxStoppableVelocity ( Displacement = 14m, Deceleration = -2m/s² ) should be 8.5m/s
MaxStoppableVelocity ( Displacement = 15m, Deceleration = -2m/s² ) should be 8.75m/s
MaxStoppableVelocity ( Displacement = 16m, Deceleration = -2m/s² ) should be 9m/s
MaxStoppableVelocity ( Displacement = 17m, Deceleration = -2m/s² ) should be 9.25m/s
MaxStoppableVelocity ( Displacement = 18m, Deceleration = -2m/s² ) should be 9.5m/s
MaxStoppableVelocity ( Displacement = 19m, Deceleration = -2m/s² ) should be 9.75m/s
MaxStoppableVelocity ( Displacement = 20m, Deceleration = -2m/s² ) should be 10m/s
All of this data in the table was tested using a simulation I did, but I want to find an equation that gives me these values.
Remembering that the time of my simulation is discrete, so equations of continuous time will not work.
Let me know if you have any questions, thanks in advance
Let's consider the problem reversed in time.
Assume you have dt - time step of your simulation and it is constant.
Assume the total number of iterations is N.
Assume the current iteration is i.
A - acceleration, D - displacement, V - speed
Thus
V[i] = (i+1) * A * dt
D[N] = D = SUM (V[i] * dt) From i = 0 To N-1
D = (N-1)^2 / 2 * dt^2 * A
N = sqrt(2* D / A) / dt + 1
But N - 1 is an integer number, thus rounding
N = floor(sqrt(2D/A)/dt + 1)
So
V = floor(sqrt(2D/A)/dt + 1) * A * dt
If you don't know the value of dt, you can find it from your example
Related
I am working in PowerBI and I have a dataset showing candidate movement within hiring requisitions. Via DAX, I would like to add columns that show the time difference between certain statuses. E.g., the result would show "3" down the column for "New to Hire" and so on.
You can do this using three measures. You will need to adjust Table3 to reflect your actual table name. I also assumed that there is a column that designates a unique ID for each employee.
New to Hire:
New to Hire :=
VAR CurID =
MAX ( Table3[ID] )
VAR NewDate =
CALCULATE (
FIRSTDATE ( Table3[Date] ),
FILTER ( ALL ( Table3 ), Table3[ID] = CurID && Table3[Status] = "New" )
)
VAR HireDate =
CALCULATE (
FIRSTDATE ( Table3[Date] ),
FILTER ( ALL ( Table3 ), Table3[ID] = CurID && Table3[Status] = "Hired" )
)
RETURN
DATEDIFF ( NewDate, HireDate, DAY )
Offer to Accept:
Offer to Acccept :=
VAR CurID =
MAX ( Table3[ID] )
VAR OfferDate =
CALCULATE (
FIRSTDATE ( Table3[Date] ),
FILTER ( ALL ( Table3 ), Table3[ID] = CurID && Table3[Status] = "Offer Sent" )
)
VAR AcceptDate =
CALCULATE (
FIRSTDATE ( Table3[Date] ),
FILTER ( ALL ( Table3 ), Table3[ID] = CurID && Table3[Status] = "Offer Accepted" )
)
RETURN
DATEDIFF ( OfferDate, AcceptDate, DAY )
Offer to Hire
Offer to Hire :=
VAR CurID =
MAX ( Table3[ID] )
VAR OfferDate =
CALCULATE (
FIRSTDATE ( Table3[Date] ),
FILTER ( ALL ( Table3 ), Table3[ID] = CurID && Table3[Status] = "Offer Sent" )
)
VAR HireDate =
CALCULATE (
LASTDATE ( Table3[Date] ),
FILTER ( ALL ( Table3 ), Table3[ID] = CurID && Table3[Status] = "Hired" )
)
RETURN
DATEDIFF ( OfferDate, HireDate, DAY )
I am trying to convert a strategy Pine Script into a study one to just plot buy and sell signals, but I can't figure out how to make the function plotshape work. I keep getting error message:
Cannot call 'plotshape' with arguments (series[bool], style=const
string, text=literal string, color=const color, size=const string,
location=const string, transp=literal bool); available overloads:
plotshape(series[bool], const string, input string, input string,
series[color], input integer, series[integer], const string,
series[color], const bool, const string, input integer, const integer,
string) =void; plotshape(<arg_series_type>, const string, input
string, input string, <arg_color_type>, input integer,
series[integer], const string, <arg_textcolor_type>, const bool, const
string, input integer, const integer, string) =void
Where's the error?
//#version=4
study(title="Trend Following Long Only", overlay=true)
lookback_length = input(200, type=input.integer, minval=1,
title="Lookback Length") smoother_length = input(3,
type=input.integer, minval=1, title="Smoother Length") atr_length =
input(10, type=input.integer, minval=1, title="ATR Length")
atr_multiplier = input(0.5, type=input.float, minval=0.0, title="ATR
Multiplier")
vola = atr(atr_length) * atr_multiplier price = sma(close, 3)
l = ema(lowest(low, lookback_length), smoother_length) h =
ema(highest(high, lookback_length), smoother_length) center = (h + l)
* 0.5 upper = center + vola lower = center - vola trend = ema(price upper ? 1 : (price < lower ? -1 : 0), 3) c1 = trend < 0 ? upper :
(trend 0 ? lower: center)
buy_signal = crossover(trend, 0) plotshape(buy_signal ? true : na,style=shape.triangleup,text="Buy",color=color.green,size=size.small,location=location.belowbar,transp=false)
sell_signal = crossunder(trend, 0) plotshape(sell_signal ? true :
na,style=shape.triangledown,text="Sell",color=color.red,size=size.small,location=location.abovebar,transp=false)
phigh = plot(h, color=color.green) plow = plot(l, color=color.red)
pcenter = plot(center, color=color.black) pclose = plot(close,
transp=100)
clr = trend 0.0 ? color.green : (trend < -0.0 ? color.red :
color.yellow) fill(pcenter, pclose, color=clr, transp=85) fill(phigh,
pcenter, color=color.green, transp=95) fill(plow, pcenter,
color=color.red, transp=95)
The problem was that you were using a boolean for the transp= argument in plotshape().
The transp argument must be an integer from 0 to 100.
This will work:
//#version=4
study(title="Trend Following Long Only", overlay=true)
lookback_length = input(200, type=input.integer, minval=1, title="Lookback Length")
smoother_length = input(3, type=input.integer, minval=1, title="Smoother Length")
atr_length = input(10, type=input.integer, minval=1, title="ATR Length")
atr_multiplier = input(0.5, type=input.float, minval=0.0, title="ATR Multiplier")
vola = atr(atr_length) * atr_multiplier
price = sma(close, 3)
l = ema(lowest(low, lookback_length), smoother_length)
h = ema(highest(high, lookback_length), smoother_length)
center = (h + l) * 0.5
upper = center + vola
lower = center - vola
trend = ema(price > upper ? 1 : (price < lower ? -1 : 0), 3)
c1 = trend < 0 ? upper : (trend > 0 ? lower : center)
buy_signal = crossover(trend, 0)
plotshape(buy_signal,style=shape.triangleup,text="Buy",color=color.green,size=size.small,location=location.belowbar,transp=80)
sell_signal = crossunder(trend, 0)
plotshape(sell_signal,style=shape.triangledown,text="Sell",color=color.red,size=size.small,location=location.abovebar,transp=80)
phigh = plot(h, color=color.green)
plow = plot(l, color=color.red)
pcenter = plot(center, color=color.black)
pclose = plot(close,transp=100)
clr = trend > 0.0 ? color.green : (trend < -0.0 ? color.red : color.yellow)
fill(pcenter, pclose, color=clr, transp=85)
fill(phigh, pcenter, color=color.green, transp=95)
fill(plow, pcenter, color=color.red, transp=95)
I use some functions in my main code which they return some values (scalar).
These values will compare in main code.
But when I run the code it has this Error:
"ERROR: MethodError: no method matching isless(::Array{Float64,1}, ::Array{Float64,1})"
Please help me. This is the code:
using JuMP, CPLEX
ZT = [-36 ; -244.5 ];
ZB = [27.149 ; -288.747];
M = 5;
model = CreateModel();
WES = model[1];
f1 = model[2]; f2 = model[3];
rf1 = model[4]; rf2 = model[5];
lf1 = model[6]; lf2 = model[7];
x = WES[:x] ; y = WES[:y] ;
JuMP.setRHS( rf1, ZB[1] ); JuMP.setRHS( lf1, ZT[1] );
JuMP.setRHS( rf2, ZT[2] ); JuMP.setRHS( lf2, ZB[2] );
ZI, ofvInt = Intpoint( ZB, ZT );
Hgap, Vgap, ZG, ofvGap = Gappoint( ZB, ZT );
if ofvInt !== NaN
y = ZI[2];
elseif ofvGap !== NaN
if isless( Hgap, M + Vgap ) # "MethodError: no method matching
# isless(::Array{Float64,1}, ::Array{Float64,1})"
y = ZG[1]
end
y = ZG[2];
else
y = ( ZB[2] + ZT[2] ) / 2;
end
I made a very simple app with a some simple functions and it is working very well on the corona simulator as in the Screen shot but when i built an APK file i got the following error when i opened the app on my phone "c:\Users\Moamen\Documents\Corona projects\Learning\main.lua:36:attempt to index global 'an'(a nil value) "
This is the app error:
Photo for the app on corona simulator:
and this is the Working folder
code:
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
-- Your code here
sound = audio.loadStream( "test2.mp3" )
ssound = audio.loadSound( "test.wav")
function com( )
audio.play( ssound )
audio.setVolume( .5)
--body
end
local options={duration = 10000 , onComplete = com }
audio.play( sound )
audio.setVolume( .25 )
group = display.newGroup()
function Puse( event)
if ("began" == event.phase) then
audio.pause()
end
-- body
end
function Resume( event)
if ("began" == event.phase) then
audio.resume( )
end
--body
end
--local widget = require("widget")
--widget.setTheme( "widget_theme_ios" )
an = display.newImage( "bg.JPG" ,150,250 )
an.xScale = .3
an.yScale = .7
--aa = display.newImageRect("bg2.JPG",100,100)
--aa.x=160
--aa.y=230
text1 =display.newText({text= "TechForm" , x=455 , y= 1 , fontSize=("60")})
transition.to( text1, {x=150,y=1,time =2000} )
text2=display.newText({text= "The android app that made by " , x=455 , y= 70 , fontSize=("20")})
transition.to( text2, {x=160,y=70,time =4000} )
text3=display.newText({text= "Moamen Hassaballah " , x=460 , y= 120 , fontSize=("30")})
transition.to( text3, {x=160,y=120,time =5000} )
--display.newImage("ando.png",160 ,350)
--display.newCircle( 300, 300, 10 )
rect = display.newRect( 170, 475, 400, 100 )
rect:setFillColor(.117,.244,.244)
ttext=display.newText({text="Thanks for using our app", x=150, y=470 ,fontSize=25} )
--rect:removeSelf( )
function Touching( event)
if ("began" == event.phase) then
x=math.random( .1,.9 )
y=math.random( .1,.9 )
z=math.random( .1,.9 )
rect:setFillColor( x,y,z )
end
end
rect2=display.newRect( 70, 387, 125, 23 )
rect:addEventListener( "touch", Touching )
button = display.newImage("button.png",60,334)
button.xScale=.4
button.yScale=.4
function ch_color( event)
if ("began" == event.phase) then
x=math.random( .1,.9 )
y=math.random( .1,.9 )
z=math.random( .1,.9 )
text3:setFillColor( x,y,z )
end
end
rect2:addEventListener( "touch", ch_color )
local widget = require("widget")
widget.setTheme( "widget_theme_ios" )
function login(event)
if ("began" == event.phase) then
rect:removeSelf( )
function login2( event)
if ("began" == event.phase) then
rect = display.newRect( 170, 475, 400, 100 )
rect:setFillColor(.117,.244,.244)
rect:addEventListener( "touch", Touching )
ttext:toFront( )
btn = widget.newButton{top=365,left=150 , label="Login" , onEvent=login}
btn.xScale=.8
btn.yScale=.7
end
-- body
end
btn = widget.newButton{top=365,left=150 , label="Login" , onEvent=login2}
btn.xScale=.8
btn.yScale=.7
end
-- body
end
local btn = widget.newButton{top=365,left=150 , label="Login" , onEvent=login}
btn.xScale=.8
btn.yScale=.7
local bb = widget.newButton{ label = "Puse" , top = 250 , left = 150 ,onEvent=Puse}
bb.xScale=.8
bb.yScale=.7
local bb2 = widget.newButton{ label = "Resume" , top = 250 , left = 2 ,onEvent=Resume }
bb2.xScale=.8
bb2.yScale=.7
function handleTabBarEvent(event)
if event.phase == "press" then
print ("Tab " .. event.target._id .. " is selected")
transition.to( cc, {x= -160 , y=220 , time=200} )
end
end
cc = display.newText( {text = "Shows Tap is selected" , x=-160 , y=220, fontSize = 30} )
function shows(event )
if (event.phase=="press") then
print( "shows tap is selected" )
transition.to( cc, {x= 160 , y=220 , time=400} )
end
-- body
end
-- Configure the tab buttons to appear within the bar
local progressView = widget.newProgressView
{
left = 10,
top = 320,
width = 300,
isAnimated = true
}
-- Set the progress to 50%
function progress_to_0(event)
if event.phase=="press"then
xx = math.random( 0.1 , 0.9 )
progressView:setProgress( 0.1 )
transition.to( cc, {x= -160 , y=220 , time=200} )
end
end
function progress_to_25(event)
if event.phase=="press"then
progressView:setProgress( 0.25 )
transition.to( cc, {x= -160 , y=220 , time=200} )
end
end
function progress_to_75(event)
if event.phase=="press"then
progressView:setProgress( 0.75 )
transition.to( cc, {x= -160 , y=220 , time=200} )
end
end
function progress_to_1(event)
if event.phase=="press"then
progressView:setProgress( 1 )
print( "shows tap is selected" )
transition.to( cc, {x= 160 , y=220 , time=400} )
end
end
local tabButtons = {
{
label = "Tab1", -- Text of the label
selected = true, -- Default selection
size = 16, -- size of the font in the Tab
onPress = progress_to_0 -- listener attached to the Tab
},
{
label = "Tab2", -- Text of the label
size = 16, -- size of the font in the Tab
onPress = progress_to_25 -- listener attached to the Tab
},
{
label = "Tab3", -- Text of the label
size = 16, -- size of the font in the Tab
onPress = progress_to_75
-- listener attached to the Tab
},{label="Shows" , size=16, onPress=progress_to_1 }
}
-- Create the Tabs object
local testTabs = widget.newTabBar
{
top = -45,
width = display.contentWidth,
height = 70,
buttons = tabButtons,
}
Android is case sensitive but Windows is (generally) case insensitive. So replace bg.JPG with bg.jpg and rename file accordingly.
Note:
Use small letters for file names,
Use local variables where possible e.g. local an = display.newImage( "bg.jpg" ,150,250 )
I'm trying to huge graph visualization with threejs r86(latest master version), for showing 600,000 nodes I found a way to draw them faster than using mesh with THREE.points but know I need to make them draggable, after many searches I found raycast to found closest object to mouse point but I have a problem becouse all of taht points are just an object and can not be changed seperately.
function Graph3(Nodes, Edges) {
this.renderer = new THREE.WebGLRenderer({ alpha: true});
var width = window.innerWidth , height = window.innerHeight;
this.renderer.setSize(width, height, false);
document.body.appendChild(this.renderer.domElement);
this.scene = new THREE.Scene(),
this.camera = new THREE.PerspectiveCamera(100, width / height, 0.1, 3000),
this.controls = new THREE.OrbitControls(this.camera);
this.controls.enableKeys = true;
this.controls.enableRotate = false;
var material, geometry;
self = this;
material = new THREE.LineBasicMaterial({color: '#ccc'});
geometry = new THREE.Geometry();
geometry.vertices = Nodes.map(function(item){return new THREE.Vector3(item.pos.x,item.pos.y,item.pos.z);});
// this.vertices = geometry.vertices;
this.line = new THREE.LineSegments(geometry, material);
this.scene.add(this.line);
var Node = new THREE.Group();
material = new THREE.PointsMaterial( { color:0x000060 ,size:1 } );
this.particles = new THREE.Mesh(geometry,material)
this.particles = new THREE.Points( geometry, material);
this.scene.add( this.particles );
dragControls = new THREE.DragControls([this.particles], this.camera/*,this.scene*/, this.renderer.domElement);
this.camera.position.z = 200;
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
document.addEventListener( 'click', function ( event ) {
// calculate mouse position in normalized device coordinates
// (-1 to +1) for both components
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
console.log(mouse);
}, false );
stats = new Stats();
document.body.appendChild(stats.dom);
this.animate = function()
{
raycaster.setFromCamera( mouse, self.camera );
var intersections = raycaster.intersectObject( self.particles );
intersection = ( intersections.length ) > 0 ? intersections[ 0 ] : null;
if ( intersection !== null) {
console.log(intersection);
}
requestAnimationFrame( self.animate );
stats.update();
self.renderer.render(self.scene, self.camera);
}
this.animate();}
I had able to change all the points with dragControls but can't move them seperatly
I had found EventsControls.js file which help us to handle events but I couldn't use it
Here you can check how to target individual parts of a buffer geometry with a raycaster:
https://github.com/mrdoob/three.js/blob/master/examples/webgl_interactive_buffergeometry.html
As for moving them, refer to this question and answer:
How to quickly update a large BufferGeometry?
Thanks for helping me in previous question.
I am making my points in 2d plane (z = 0) and I could making them with bufferGeometry and RawShaderMaterial but now I have another problem in dragging them, how raycaster do? it need vec3 positions but I have changed it for performance purpose.
var Geo = new THREE.BufferGeometry();
var position = new Float32Array( NodeCount * 2 );
var colors = new Float32Array( NodeCount * 3 );
var sizes = new Float32Array( NodeCount );
for ( var i = 0; i < NodeCount; i++ ) {
position[ 2*i ] = (Math.random() - 0.5) * 10;
position[ 2*i + 1 ] = (Math.random() - 0.5) * 10;
colors[ 3*i ] = Math.random();
colors[3*i+1] = Math.random();
colors[3*i+2] = Math.random();
// sizes
sizes[i] = Math.random() * 5 ;
}
Geo.addAttribute( 'position', new THREE.BufferAttribute( position, 2 ) );
Geo.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
Geo.addAttribute( 'size', new THREE.BufferAttribute( sizes, 1 ) );
points = new THREE.Points( Geo, new THREE.RawShaderMaterial({
vertexShader:`
precision highp float;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform vec3 cameraPosition;
attribute vec2 position; /// reason of problem
varying vec3 vColor;
attribute vec3 color;
attribute float size;
void main() {
vColor = color;
gl_PointSize = size;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position , 0, 1 );
}`,
fragmentShader:`
precision highp float;
varying vec3 vColor;
void main() {
gl_FragColor = vec4( vColor, 1.0 ) ;
}`
}) );
scene.add( points );
and my using of raycaster:
function mouseDown(e) {
e.preventDefault();
var mouse = new THREE.Vector2();
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
// mouse.z = 0;
raycaster.setFromCamera(mouse, camera);
raycaster.far = camera.position.z + 3;
const intersect = raycaster.intersectObject(points);
console.log(intersect);
if (intersect.length > 0) {
controls.enabled = false;
console.log(intersect);
selection = intersect[0].index;
}
}
function mouseUp(e) {
controls.enabled = true;
var vector = new THREE.Vector3();
vector.x = (( event.clientX / window.innerWidth ) * 2 - 1);
vector.y = (- ( event.clientY / window.innerHeight ) * 2 + 1);
vector.z = 1.0;
console.log(camera.position.z);
vector.unproject( camera );
var dir = vector.sub( camera.position ).normalize();
var distance = - camera.position.z / dir.z;
var temp = camera.position.clone().add( dir.multiplyScalar( distance ) );
var pos = points.geometry.attributes.position;
pos.setXY(selection, temp.x, temp.y);
pos.updateRange.offset = selection; // where to start updating
pos.updateRange.count = 1; // how many vertices to update
pos.needsUpdate = true;
selection = undefined;
}