gpt4 book ai didi

algorithm - 计算半铰接卡车的位移坐标

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:41:40 27 4
gpt4 key购买 nike

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

enter image description here

卡车拉着拖车。

拖车根据卡车上的对接轴移动。

然后,当卡车转弯时,拖车应逐渐与卡车的新角度对齐,就像在现实生活中一样。

我想知道是否有任何公式或算法可以简单地进行此计算。

我已经看过逆向运动学方程,但我认为只要两部分就不会那么复杂。

谁能帮帮我?

最佳答案

A为前轴下中点,B为中轴下中点,C为前轴下中点后轴。为简单起见,假设 Hook 位于 B 点。这些都是时间 t 的函数,例如 A(t) = (a_x(t), a_y(t)

技巧是这样的。 B 直接朝 A 移动,其中 A 在该方向上的速度分量。或者在符号中,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你最喜欢的语言和你最喜欢的线性代数库。甚至手动滚动。

在我的示例中,我从 A 开始于 (1, 1)B 开始于 (2, 1)C(2, 2)。然后以 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 )

关于algorithm - 计算半铰接卡车的位移坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50107516/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com