POV-Ray : Newsgroups : povray.animations : simple kinematic Server Time
23 Nov 2024 06:32:18 EST (-0500)
  simple kinematic (Message 1 to 4 of 4)  
From: CAD-Andi
Subject: simple kinematic
Date: 2 Feb 2014 16:50:01
Message: <web.52eebd7caf6a8b45bf952ed30@news.povray.org>
Hi!
I would like to simulate a tractor-trailer situation. The vehicle should be
guided by a spline and the trailer will be connected on a pivot point.

The main problem is the so called "off tracking" of the trailer when the
combination goes through a turn. The rear end of the trailer describes a
different path than the pulling vehicle.

I need to do this only on a plane in 2D (for now). Does anyone have a idea or
even a little code snippet to put me on track? Did anyone come a cross a inverse
kinematics script for POVRay? ...

Thanks!


Post a reply to this message

From: Jeff Reifel
Subject: Re: simple kinematic
Date: 6 Feb 2014 17:20:01
Message: <web.52f40a00493122f911fab0250@news.povray.org>
"CAD-Andi" <nomail@nomail> wrote:
> Hi!
> I would like to simulate a tractor-trailer situation. The vehicle should be
> guided by a spline and the trailer will be connected on a pivot point.
>
> The main problem is the so called "off tracking" of the trailer when the
> combination goes through a turn. The rear end of the trailer describes a
> different path than the pulling vehicle.
>
> I need to do this only on a plane in 2D (for now). Does anyone have a idea or
> even a little code snippet to put me on track? Did anyone come a cross a inverse
> kinematics script for POVRay? ...
>
> Thanks!
I played around with your problem and came up with this. It might need some fine
tunning.
#version 3.7;
global_settings { max_trace_level 20
assumed_gamma 1.0 }

#declare C= clock*18+1;

#declare SPLINE=spline{quadratic_spline
 0,<-242.85714,348.57143262>
,1,<-242.85714,371.42857262>,2,<-191.42857,440.00000262> ,
 3,<-42.857143,525.71428262>,4,<171.42857,502.85714262>,5,<288.57143,440.00000262>,
 6,<374.28571,325.71428262>,7,<425.71429,205.71428262>,8,<285.71429,168.57143262>,
 9,<234.28571,288.57143262>,10,<162.85714,405.71428262>,11,<20,428.57143262>,
 12,<-54.285714,377.14285262>,13,<-102.85714,245.71428262>,14,<8.5714286,225.71428262>,
 15,<14.285714,145.71428262>,16,<-71.428571,122.85714262>,17,<-217.14286,182.85714262>,
 18,<-282.85714,254.28571262>,19,<-242.85714,348.57143262> }

#declare X_FOLLOW = SPLINE(C).x;
#declare Y_FOLLOW = SPLINE(C).y;
#declare X_CAB_LEAD = SPLINE(C+1.5).x;
#declare Y_CAB_LEAD = SPLINE(C+1.5).y;
#declare X_TOW_LEAD = SPLINE(C+.5).x;
#declare Y_TOW_LEAD = SPLINE(C+.5).y;
#declare X_DIFFER  = X_FOLLOW-X_TOW_LEAD;
#declare Y_DIFFER =  Y_FOLLOW-Y_TOW_LEAD;

#if(Y_DIFFER=0)#declare Y_DIFFER=.001;
   #end
#declare REF_ANGLE=0;
#if  (Y_DIFFER<0)
        #if  (X_DIFFER<0)   #declare REF_ANGLE=-180+atan(X_DIFFER/Y_DIFFER);
             #else #declare REF_ANGLE=180+(atan (X_DIFFER/Y_DIFFER));
   #end
           #end

#declare POINT =-(180/pi)*atan(X_DIFFER/Y_DIFFER)-REF_ANGLE;

#declare X_DIFFER_CAB  = X_CAB_LEAD-X_FOLLOW;
#declare Y_DIFFER_CAB = Y_CAB_LEAD- Y_FOLLOW;
 #if(Y_DIFFER_CAB=0)#declare Y_DIFFER_CAB=.001;#end
 #declare REF_ANGLE=0;
 #if  (Y_DIFFER_CAB<0)
        #if  (X_DIFFER_CAB<0)   #declare
REF_ANGLE=-180+atan(X_DIFFER_CAB/Y_DIFFER_CAB);
             #else #declare P=z; #declare REF_ANGLE=180+(atan
(X_DIFFER_CAB/Y_DIFFER_CAB));
 #end
        #end
   #declare POINT_CAB =180-(180/pi)*atan(X_DIFFER_CAB/Y_DIFFER_CAB)-REF_ANGLE;


union{cylinder{5*y,25*y,6.5} cone{0,0,5*y,6.5} cylinder{-.25*z,.25*z,2.5 }

rotate <0,0,POINT>
 translate<X_TOW_LEAD,Y_TOW_LEAD,0    >/3

 pigment{rgb 0} }
  union{cylinder{-5*y,-10*y,6.5} cone{0,0,-5*y,6.5}

rotate <0,0,POINT_CAB>
 translate<X_TOW_LEAD,Y_TOW_LEAD,0    >/3

 pigment{rgb 0} }
  //////ROAD
  #declare I=0;
   #while (I<19)
  cylinder{0,z,11 translate SPLINE(I)/3 pigment{rgb<1,1,0>} finish{ambient 1}}
  cylinder{-z/99,z,1 translate SPLINE(I)/3 pigment{rgb<0,0,0>} }
   #declare I=I+.1;
   #end

camera{  orthographic //angle 5
location<16,122,-100>
 #declare Wide=70;
up    <0,3.0,0> *Wide
right  <4,0,0> *Wide
look_at <16,122,0>}

background{rgb  1}


Post a reply to this message

From: CAD-Andi
Subject: Re: simple kinematic
Date: 11 Feb 2014 10:35:02
Message: <web.52fa41b5493122f9ec12b4220@news.povray.org>
"Jeff Reifel" <jef### [at] rocketmailcom> wrote:

> I played around with your problem and came up with this. It might need some fine
> tunning.

Thank you Jeff! Thank you so much for the code! Nothing is worst for me than to
start out with an absolute empty page without anything on it. With the help of
you kickstarting me I might just get to a solution for my problem.

You were right, it might need some "tweaking" :-) I'm a very visual oriented
person and a look at the finished rendered anim made it very easy for me to
follow your code: In simple words you used the clock and set values (Truck 1.5,
and Trailer 0.5) to "look into the future" and "anticipate" the angle of turning
by calculating the angle of the line between now and then (two points) and the
current tangent trajectory. You made the hinge point move on the spline and used
the "delayed" reaction of the trailer to create the "illusion" of the trailer
"following" the truck. ... Very clever and simple approach!

In "theory" I have a solution for my problem, But I'm missing one important
example. How to calculate an intersection point of a circle-arc with a spline in
POVRay. Is this possible? If not, then there is no need to read further on,
because my Idea is based on this. Please someone let me know.

For my purpose I come to the realization that I will have to work with 2
splines. One for the Tractor and one for the Trailer. The geometry of these
splines will be determined by external software. There is one key calculation
that I need to accomplish to pull this off. I must know how to calculate an
intersection point of a circle-arc (or sphere segment) with a spline in POVRay.

There will be two arcs. One for the Tractor and one for the Trailer. I imagine a
point moving along the Truck spline. This is the point between the front wheels.
I need to figure out the position of the 5th wheel on the spline. I plan on
doing this by getting the coordinates of the intersection of the spline with an
circular arc of lets say +/- 45 deg with the radius equal to the distance
between the front axis point to the 5th wheel. That will determine my two vector
points for the tractor orientation. (I plan on using the arc instead of the full
circle to avoid getting multiple results.)

Next I do exactly the same with the distance between that 5th wheel point and
the center between my rear trailer wheels for the second arc radius,
intersecting it with my rear trailer path spline. That will give me the vector
for the Trailer orientation.

I can (and have) simulated that in CAD, but I need to get this done in POVRay to
save me from doing it all "by hand" point by point. This would also allow me to
use the distance of my first spline nodes for determining the speed of my truck.

Sorry for this long post, but I just don't know how to express what I need to
accomplish using less words.

Thanks for all your help!

Andi


Post a reply to this message

From: CAD-Andi
Subject: Re: simple kinematic
Date: 11 Feb 2014 16:20:01
Message: <web.52fa92e1493122f9ec12b4220@news.povray.org>
"CAD-Andi" <nomail@nomail> wrote:
> "Jeff Reifel" <jef### [at] rocketmailcom> wrote:
>
> > I played around with your problem and came up with this. It might need some fine
> > tunning.
>
> Thank you Jeff! Thank you so much for the code! Nothing is worst for me than to
> start out with an absolute empty page without anything on it. With the help of
> you kickstarting me I might just get to a solution for my problem.
>

And here it is!!! I simplified and used a iterative approach with a very small
increment that does the trick for me. Like a blind person (Please no offense
intended) I'm "feeling" my way on the spline along the time-line and compare the
distance of the point reached with the distance I want to get. That prevents me
from having to calculate intersecting geometry all together and should always
work! :-) I'm making use of the "math.inc" include file.

This gives me what I was after, if someone has a more elegant / flexible
solution ... don't hold yourself back posting it. I'm all ears! Every time I got
in contact with anyone here I got help and was able to find a solution for my
coding problems! You guys are great! Thanks a million!

Andi

Here is my messy code:

#version 3.7;
global_settings { max_trace_level 20
assumed_gamma 1.0 }
#include "math.inc"

#declare C= clock*18;

#declare TIME_INDEX_START = 2;
#declare INCREMENT = .001;

#declare DIRECTION_REFERENCE = y;

#declare SPLINE=spline{quadratic_spline
 0,<-242.85714,348.57143262>
,1,<-242.85714,371.42857262>,2,<-191.42857,440.00000262> ,
 3,<-42.857143,525.71428262>,4,<171.42857,502.85714262>,5,<288.57143,440.00000262>,
 6,<374.28571,325.71428262>,7,<425.71429,205.71428262>,8,<285.71429,168.57143262>,
 9,<234.28571,288.57143262>,10,<162.85714,405.71428262>,11,<20,428.57143262>,
 12,<-54.285714,377.14285262>,13,<-102.85714,245.71428262>,14,<8.5714286,225.71428262>,
 15,<14.285714,145.71428262>,16,<-71.428571,122.85714262>,17,<-217.14286,182.85714262>,
 18,<-282.85714,254.28571262>,19,<-242.85714,348.57143262> }


#declare X_CAB_FRONT = SPLINE(C+ TIME_INDEX_START).x;
#declare Y_CAB_FRONT = SPLINE(C+ TIME_INDEX_START).y;

#declare LENGTH_CAB = 30;
#declare LENGTH_TRAILER = 60;
#declare INDEX = .001;

#declare CAB_DIST = VDist(<X_CAB_FRONT, Y_CAB_FRONT,0>, <SPLINE(C+
TIME_INDEX_START+INDEX).x, SPLINE(C+ TIME_INDEX_START+INDEX).y,0>);

#while (CAB_DIST <= LENGTH_CAB)
 #declare INDEX = INDEX - INCREMENT;
 #declare CAB_DIST = VDist(<X_CAB_FRONT, Y_CAB_FRONT,0>,
<SPLINE(C+TIME_INDEX_START+INDEX).x, SPLINE(C+TIME_INDEX_START+INDEX).y,0>);

#end
 #declare FIFTH_WHEEL =  <SPLINE(C+TIME_INDEX_START+INDEX).x,
SPLINE(C+TIME_INDEX_START+INDEX).y,0>;
 #declare output = concat("Frame: ",str(frame_number,0,0)," Clock
is:",str(clock,0,3),  "  INDEX is ",str(INDEX,0,3), "   FIFTH_WHEEL =
","<",str(FIFTH_WHEEL.x,0,3) ,",",str(FIFTH_WHEEL.y,0,3),",0>"  ,  " CAB_DIST =
",str(CAB_DIST,0,3),"\n");
    #debug output


#declare TRAILER_DIST = VDist(FIFTH_WHEEL, <SPLINE(C+ TIME_INDEX_START+INDEX).x,
SPLINE(C+ TIME_INDEX_START+INDEX).y,0>);

#while (TRAILER_DIST <= LENGTH_TRAILER)
    #declare INDEX = INDEX - INCREMENT;
  #declare TRAILER_DIST = VDist(FIFTH_WHEEL,
<SPLINE(C+TIME_INDEX_START+INDEX).x, SPLINE(C+TIME_INDEX_START+INDEX).y,0>);

#end
 #declare TRAILER_END =  <SPLINE(C+TIME_INDEX_START+INDEX).x,
SPLINE(C+TIME_INDEX_START+INDEX).y,0>;
 #declare output = concat("Frame: ",str(frame_number,0,0)," Clock
is:",str(clock,0,3),  "  INDEX is ",str(INDEX,0,3), "   TRAILER_END =
","<",str(TRAILER_END.x,0,3) ,",",str(TRAILER_END.y,0,3),",0>"  ,  " CAB_DIST =
",str(TRAILER_DIST,0,3),"\n");
    #debug output

cylinder{<0,0,0>,<0,0,-2>,2 translate <X_CAB_FRONT, Y_CAB_FRONT,0>/3
pigment{rgb<1,0,0>} }
cylinder{<0,0,0>,<0,0,-2>,2 translate FIFTH_WHEEL/3 pigment{rgb<0,1,0>} }
cylinder{<0,0,0>,<0,0,-2>,2 translate TRAILER_END/3 pigment{rgb<0,0,1>} }

//figure out ANGLE_CAB
#declare DIRECTION_CAB = FIFTH_WHEEL- <X_CAB_FRONT, Y_CAB_FRONT,0>;
#declare ANGLE_CAB = VAngleD(DIRECTION_CAB,DIRECTION_REFERENCE);


union{cylinder{0*y,5*y,6.5} cone{<0,5,0>,6.5,<0,10,0>,0}


#if (DIRECTION_CAB.y > 0 & DIRECTION_CAB.x > 0 )
 rotate <0,0, +(ANGLE_CAB*-1)>
#end
#if (DIRECTION_CAB.y > 0 & DIRECTION_CAB.x < 0 )
  rotate <0,0, +(ANGLE_CAB*1)>
#end
#if (DIRECTION_CAB.y < 0 & DIRECTION_CAB.x > 0 )
    rotate <0,0, +(ANGLE_CAB*-1)>
#end
#if (DIRECTION_CAB.y < 0 & DIRECTION_CAB.x <0 )
      rotate <0,0, +(ANGLE_CAB*1)>
#end

  translate<X_CAB_FRONT, Y_CAB_FRONT,0>/3
 pigment{rgb 0} }


//Figure out ANGLE_TRAILER
#declare DIRECTION_TRAILER = TRAILER_END  - FIFTH_WHEEL;
#declare ANGLE_TRAILER = VAngleD(DIRECTION_TRAILER,DIRECTION_REFERENCE);


union{cylinder{20*y,5*y,6.5} cone{<0,5,0>,6.5,<0,0,0>,0}
#if (DIRECTION_TRAILER.y > 0 & DIRECTION_TRAILER.x > 0 )
 rotate <0,0, +(ANGLE_TRAILER*-1)>
#end
#if (DIRECTION_TRAILER.y > 0 & DIRECTION_TRAILER.x < 0 )
  rotate <0,0, +(ANGLE_TRAILER*1)>
#end
#if (DIRECTION_TRAILER.y < 0 & DIRECTION_TRAILER.x > 0 )
    rotate <0,0, +(ANGLE_TRAILER*-1)>
#end
#if (DIRECTION_TRAILER.y < 0 & DIRECTION_TRAILER.x <0 )
      rotate <0,0, +(ANGLE_TRAILER*1)>
#end

  translate FIFTH_WHEEL/3
 pigment{rgb 0} }



// zero spline
//cylinder{<0,0,0>,<0,0,-2>,6 translate SPLINE(2)/3 pigment{rgb<1,0,1>} }


 //////ROAD
  #declare I=0;
   #while (I<19)
  cylinder{0,z,11 translate SPLINE(I)/3 pigment{rgb<1,1,0>} finish{ambient 1}}
  cylinder{-z/99,z,1 translate SPLINE(I)/3 pigment{rgb<0,0,0>} }
   #declare I=I+.1;
   #end

camera{  orthographic //angle 5
location<16,122,-100>
 #declare Wide=70;
up    <0,3.0,0> *Wide
right  <5.33333333,0,0> *Wide
look_at <16,122,0>}

background{rgb  1}


Post a reply to this message

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