POV-Ray : Newsgroups : povray.advanced-users : Truck and trailer : Re: Truck and trailer Server Time
29 Jul 2024 14:17:59 EDT (-0400)
  Re: Truck and trailer  
From: J  Diehl
Date: 29 Aug 2002 17:15:06
Message: <web.3d6e8dc9a31ba4aac82a5e2b0@news.povray.org>
Yeah, that's it! I just wrote a simulation in Visual Basic (code see below).
Didn't think it would really work so naturally! It feels really great, you
can even drive backwards with a trailer! And it's easy to add as many
trailers as you want. :-)))

I made some drawings to illustrate the description above. Since I can't post
attachments here, you will have to download it as PDF from my server (need
the Acrobat Reader from adobe.com - it's free)

http://enter.diehlsworld.de/raytracing/truck.pdf

BTW, Thomas, you were on the right way with your first posting: the angle
and the whole behavior just depends on the length of the trailer.

Perhaps this weekend, I will try a POV-implementation that will be posted
here when working... (it will need more trigonometry than the VB-script
below)

And here the VB-code:
----------------------------
Rem Truck-Trailer-Problem
Rem Visual Basic Script
Rem (c) 2002 by J. Diehl
Rem http://enter.diehlsworld.de

Rem make a form with a picture object called 'picture1' and paste this code
into the codeview
Rem start the program and move the mouse over the picture

Rem Data for the trailers 1-3
Rem cx,cy the pole where the trailer will be pulled
Rem ax,ay the middle of the axis (and the coupling for the next trailer)
Dim cx1, cy1, ax1, ay1
Dim cx2, cy2, ax2, ay2
Dim cx3, cy3, ax3, ay3


Rem do a drive-step for any trailer
Rem where myax,myay,mycx,mycy are the specific trailer data to be modified
in this step
Rem newx,newy: the target for the pole in this step
Rem length: the length of the pole
Public Sub drive(ByRef myax, ByRef myay, ByRef mycx, ByRef mycy, newx, newy,
length)

Rem get the vector axis - new position
dx = newx - myax
dy = newy - myay

Rem set the trailer along this vector and move it to the new position
d = Sqr(dx * dx + dy * dy)
tomove = d - length
myax = myax + dx / d * tomove
myay = myay + dy / d * tomove

Rem draw the trailer
Picture1.Circle (myax, myay), 4, 0
Picture1.Circle (newx, newy), 2, 255
wx = (newx - myax) / length * 20
wy = (newy - myay) / length * 20
Picture1.Line (-wy + myax, wx + myay)-(wy + myax, -wx + myay), 255
Picture1.Line (-wy + myax, wx + myay)-(newx, newy), 255
Picture1.Line (wy + myax, -wx + myay)-(newx, newy), 255

End Sub

Private Sub Form_Load()
Rem set ScaleMode pixel for graphic output
Picture1.ScaleMode = 3
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)

Rem clear screen and get user mouse position
Picture1.Cls
px = X
py = Y

Rem first trailer drives to px,py (user-position)
Rem next trailer drives to the middle of the axis of the previous trailer
and so on...
drive ax1, ay1, cx1, cy1, px, py, 50
drive ax2, ay2, cx2, cy2, ax1, ay1, 50
drive ax3, ay3, cx3, cy3, ax2, ay2, 130

End Sub

----------

That's all!
Have a nice time with it...
Jo


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.