|
|
"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
|
|
|
|
"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
|
|