Robotnačka v Metaposte

From RoboWiki
Jump to: navigation, search

Aby sme mohli kresliť pekné obrázky Robotnačky, použijeme Metapost. Tu je príklad aj výsledným obrázkom. Preklad:

mpost robotnacka.mp

Robotnačka v Metaposte
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
%                                                            %
% This is a simple example how to draw fine pictures of the  %
% Robotnacka robot for the kinematics modelling.             %
%                                                            %
% (c) Richard Balogh, january 2007                           % 
% http://www.robotika.sk/                                    % 
%                                                            %
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %

% Uncomment this for use as a standalone picture, comment for use in LaTeX.
  prologues:=1;

  beginfig(1);

% Declarations and definitions
  
  picture Robotnacka;  pair P;     % Variables
  u := 48;                         % Basic measurement unit

% Body of the robot

  fill fullcircle scaled 210 withcolor (1,1,0);  % (r,g,b) = Yellow
  draw fullcircle scaled 210 withcolor red;

% Wheels

  linecap:=rounded;
  pickup pencircle scaled 5;        % Width of wheels 
  draw (-25,90)--(25,90);           % Left wheel
  draw (-25,-90)--(25,-90);         % Right wheel
  pickup pencircle scaled 1;        % Restore original fine point

% Castor wheel
  
  fill fullcircle scaled 30 shifted (-77,0) withcolor .3white;

% Help lines

  draw (0,90)--(0,-90);
  drawarrow (0,0)--(50,0) withcolor blue;

% Center of the robot:
  
  cu=10;
  draw fullcircle scaled cu withcolor red;
  path quarterdisk; quarterdisk := quartercircle--origin--cycle;
  fill quarterdisk scaled cu withcolor red;
  fill quarterdisk scaled cu rotated 180 withcolor red;
  draw (cu,0)--(-cu,0);
  draw (0,cu)--(0,-cu);

% Start to draw moving robot:

  Robotnacka = currentpicture;
  clearit;

  Theta=45;       % Orientation of the robot
  P := (5u,7u);   % Final position of the robot

  addto currentpicture also Robotnacka rotated Theta shifted P;

% Trajectory:   :-)

  pickup pencircle scaled 2;
  drawarrow origin..controls (0,3u) and (2u,0) ..(2u,2u)..{dir45}P withcolor green;

  dotlabel.lft("0",origin);


 endfig;

end;