POV-Ray : Newsgroups : povray.animations : simple kinematic : Re: simple kinematic Server Time
25 Apr 2024 04:31:46 EDT (-0400)
  Re: simple kinematic  
From: CAD-Andi
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.