Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexplained v*pi/2 factor when integrating velocity in polar coordinates #428

Open
goatchurchprime opened this issue Apr 15, 2020 · 0 comments

Comments

@goatchurchprime
Copy link

A body at position (0,0) traveling with a speed v in the direction gamma ought to be at position (v*cos(gamma)*t, v*sin(gamma)*t) by time t.

I've set all the forces to zero (requires the work-around for issue #427 with a dummy variable)

import sympy as sp
from math import radians
import sympy.physics.mechanics as me
from pydy.system import System
import numpy as np

f = sp.Symbol('f')
t = sp.Symbol('t')
x, y = me.dynamicsymbols('x y')          # cartesian position
v, gamma = me.dynamicsymbols('v gamma')  # polar velocity
xd, yd       = me.dynamicsymbols('x y', 1)
kd_eqs       = [ xd - v*sp.cos(gamma), 
                 yd - v*sp.sin(gamma) ]

BaseFrame = me.ReferenceFrame('BaseFrame')
origin  = me.Point('origin')
bodycentre  = origin.locatenew('bodycentre', x*BaseFrame.x + y*BaseFrame.y)

# either one will do
bodycentre.set_vel(BaseFrame, bodycentre.pos_from(origin).diff(t, BaseFrame))
#bodycentre.set_vel(BaseFrame, v*sp.cos(gamma)*BaseFrame.x + v*sp.sin(gamma)*BaseFrame.y)

Izz = me.outer(BaseFrame.z, BaseFrame.z)*10
body = me.RigidBody(name="body", masscenter=bodycentre, 
                       frame=BaseFrame, mass=10, inertia=(Izz, bodycentre))

forces = [ (bodycentre, f*BaseFrame.x) ]
bodies = [ body ]

KM = me.KanesMethod(BaseFrame, q_ind=[x,y], u_ind=[v,gamma], kd_eqs=kd_eqs)
fr, frstar = KM.kanes_equations(bodies, forces)

times = np.linspace(0.0, 1, 101)   # 0.01 second increments
sys = System(KM,
             constants={f:0},  # hardcoding f=0 causes issue #427
             initial_conditions={x:0, y:0, v:5, gamma:radians(90) },
             times=times)

y1 = sys.integrate()
print(times[:2])
y1[:2]

If the velocity direction is gamma:radians(0) (along x), then y1[:2] is correctly:

array([[0.  , 0.  , 5.  , 0.  ],
       [0.05, 0.  , 5.  , 0.  ]])

But if you leave it gamma:radians(90) (along y), then y1[:2] is:

array([[ 0.        ,  0.        ,  5.        ,  1.57079633],
       [-0.07853982,  0.05      ,  5.        ,  1.57079633]])

For some reason it's deciding to introduce an extra component of velocity in the x-direction of v*gamma.

I've extracted this down from the more complex model I was trying to do, but if this doesn't work, then nothing will.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant