如下图所示,我正在创建一个程序,该程序将制作由两个铰接部分组成的卡车的2D动画。

卡车拉着拖车。
拖车根据卡车上的停靠轴移动。
然后,当卡车转弯时,拖车应该逐渐与卡车的新角度对齐,就像在现实生活中一样。
我想知道是否有任何公式或算法可以简单地进行这种计算。
我已经看到了逆运动学方程,但我认为只要有两个部分,它就不会那么复杂。
有人能帮我吗?
发布于 2018-05-01 05:44:56
设A为前轴下方的中点,B为中轴下方的中点,C为后轴下方的中点。为简单起见,假设故障发生在点B。这些都是time t的函数,例如A(t) = (a_x(t), a_y(t)。
诀窍是这样的。B直接向A移动,A的速度分量在那个方向上。或者在symbols,dB/dt = (dA/dt).(A-B)/||A-B||和类似的dC/dt = (dB/dt).(B-C)/||B-C||中,.是点积。
这就变成了一个有6个变量的非线性一阶系统。这可以用普通的技术来解决,比如https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods。
更新:添加了代码
这是一个Python实现。您可以将它替换为您最喜欢的语言和线性代数库的https://rosettacode.org/wiki/Runge-Kutta_method。或者甚至是手卷。
在我的例子中,我从(1, 1)的A,(2, 1)的B和(2, 2)的C开始。然后以0.01大小的步长将A拉到原点。可以更改为您想要的任何内容。
#! /usr/bin/env python
import numpy
# Runga Kutta method.
def RK4(f):
return lambda t, y, dt: (
lambda dy1: (
lambda dy2: (
lambda dy3: (
lambda dy4: (dy1 + 2*dy2 + 2*dy3 + dy4)/6
)( dt * f( t + dt , y + dy3 ) )
)( dt * f( t + dt/2, y + dy2/2 ) )
)( dt * f( t + dt/2, y + dy1/2 ) )
)( dt * f( t , y ) )
# da is a function giving velocity of a at a time t.
# The other three are the positions of the three points.
def calculate_dy (da, A0, B0, C0):
l_ab = float(numpy.linalg.norm(A0 - B0))
l_bc = float(numpy.linalg.norm(B0 - C0))
# t is time, y = [A, B, C]
def update (t, y):
(A, B, C) = y
dA = da(t)
ab_unit = (A - B) / float(numpy.linalg.norm(A-B))
# The first term is the force. The second is a correction to
# cause roundoff errors in length to be selfcorrecting.
dB = (dA.dot(ab_unit) + float(numpy.linalg.norm(A-B))/l_ab - l_ab) * ab_unit
bc_unit = (B - C) / float(numpy.linalg.norm(B-C))
# The first term is the force. The second is a correction to
# cause roundoff errors in length to be selfcorrecting.
dC = (dB.dot(bc_unit) + float(numpy.linalg.norm(B-C))/l_bc - l_bc) * bc_unit
return numpy.array([dA, dB, dC])
return RK4(update)
A0 = numpy.array([1.0, 1.0])
B0 = numpy.array([2.0, 1.0])
C0 = numpy.array([2.0, 2.0])
dy = calculate_dy(lambda t: numpy.array([-1.0, -1.0]), A0, B0, C0)
t, y, dt = 0., numpy.array([A0, B0, C0]), .02
while t <= 1.01:
print( (t, y) )
t, y = t + dt, y + dy( t, y, dt )发布于 2018-05-01 08:57:41
通过我看到的答案,我意识到解决方案并不是真的很简单,必须通过反向运动学算法来解决。
This site就是一个例子,它只是一个开始,尽管它仍然不能解决所有问题,因为点C是固定的,并且在卡车的情况下它应该移动。
发布于 2018-05-03 22:17:05
基于这个Analytic Two-Bone IK in 2D article,我做了一个fully functional model in Geogebra,它的核心由两个简单的数学方程组成。
https://stackoverflow.com/questions/50107516
复制相似问题