Jump to content
  • Advertisement
Sign in to follow this  
4mad3u5

Rendering Engine Using Matlab, matrices and vectors

This topic is 2036 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

HI, I am a junior computer science and electrical engineering student. I have taken a calc 4 class in linear algebra and differential equations. For our final project I was given the opportunity to make a rendering engine in matlab using matrices and vectors. I created a car and four building that I could drive around. I started just by pushing around data points. I got the car to make a random decision every time the car was given the option to either take a left, right, or go straight. The car drove around randomly for however many passes I wanted to make. 

 

I took a class in computer mathematical programming next. In this classes we used matrices and vectors in matlab to create 3D rendering. I continued with my project and got the car to follow the tangent line of any function that I wanted to feed it. I also made a function where my car could go down a level or up a level. I made a 3 layer area with 3 by 3 of building where I gave the car a decision of these things: straight, left, right, spiral up to next floor, if at top floor come up from the bottom to bottom level, spiral down floor, if at bottom floor go to top floor. I would like to add an opengl api layer to it to give it some graphics. I would like to see if I could add a physics engine to this. I would also like to add a control engine to this. I would also know how far I can push this idea. Here is some of my code:

 

Here is a car doing a basic figure 8 always tangent to the line of any function you want to give to it:

echo off
syms theta
f=position(theta); 
velocity=diff(f,theta,1);





pause on
b =  0;           % x perspective view
c = 30;            % y perspective view
d = 70;            % z perspective view


x = 0;             % x theta
y = 0;
z = 0;             % z theta 


ty1 = 0;            % y location

tx2 = 0;
ty2 = 0;
tz2 = 0;
tx3 = 0;
ty3 = 0;
tz3 = 0;

sx = 1;            % x scaling factor
sy = 1;            % y scaling facotr
sz = 1;            % z scaling facotr


wxmin = -190;
wxmax = 190;
wymin = -50;
wymax = 20;


inc = pi/24;       % theta rotaion inc
inc2 = 2.3;
pse = .001;        % pause delay 



dCar = [-6.5 -6.5 -6.5 -6.5 -2.5 -2.5 -.75 -.75 3.25 3.25 4.5 4.5 6.5 6.5 6.5 6.5;
0 0 2.5 2.5 2.5 2.5 4 4 4 4 2.5 2.5 2.5 2.5 0 0;
-2.5 2.5 2.5 -2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 2.5 -2.5;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];

Trans = [1 0 0 0; 0 1 0 0; 0 0 1 1; 0 0 0 1] * dCar; % pushes DP1 off the origan 






A = [0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1;
1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0;
0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0;
1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0;
0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0;
0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0;
0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0;
0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0;
0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0;
0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0;
0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1;
0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0;
0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1;
1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0];


Zall = horzcat(A);         %entire ajacinty martic




for newstep = 0 : -pi/50 : -4*pi/1
    location=subs(f,theta,newstep);
    direction=subs(velocity,theta,newstep);
    phi = atan2(direction(2,1),direction(1,1))
    
   
    
    
    T  = [1 0 0 (80*cos(newstep)); 0 1 0 ty1; 0 0 1 (40*sin(2*newstep)); 0 0 0 1];
    
    
    
    S  =  [sx 0 0 0;0 sy 0 0;0 0 sz 0;0 0 0 1];                           % Shear Matrix

    Rx = [1 0 0            0; 0 cos(x) -sin(x) 0; 0 sin(x) cos(x) 0; 0 0 0 1];      % x Rotation matrix
    Ry = [cos(phi) 0 -sin(phi) 0; 0 1 0 0; sin(phi) 0 cos(phi) 0;0 0 0 1];     % y Rotation matrix
    Rz = [cos(z) -sin(z) 0 0; sin(z) cos(z) 0  0; 0 0 1 0 ; 0 0 0 1];    % z Rotation matrix

    P  = [1 0 -b/d 0;0 1 -c/d 0 ;0 0 0 0;0 0 -1/d 1];                    % Projection matrix
    DP = S*T*Rx*Ry*Rz*Trans;    
    D3 = horzcat(DP);

    Dpro = P * D3;  
    GP1 = Dpro(1:3,:)./[Dpro(4,:);Dpro(4,:);Dpro(4,:)];
    GP2 = GP1(1:2,:);
    D2T = transpose(GP2);
    gplot(Zall,D2T,'K')
    axis ([wxmin wxmax,wymin wymax])
    pause(pse) 
    
end

you will need the function position. From here you can control what line you want the car to follow. 

function [f] = position(theta)
f=[4*cos(theta);2*sin(2*theta)]
end

Edited by 4mad3u5

Share this post


Link to post
Share on other sites
Advertisement

car driving in circle, real basic, first I push my car's data points off the origin and then I use rotation matrices to rotate the car. 
 

pause on
b = 0;
c = 10;
x = 0;
y = 0;
z = 0;
d = 40;
tx = 0;
ty = 0;
tz = 0;
sx = 1;
sy = 1;
sz = 1;
r = 0;
DH = [-6.5 -6.5 -6.5 -6.5 -2.5 -2.5 -.75 -.75 3.25 3.25 4.5 4.5 6.5 6.5 6.5 6.5;
-2 -2 .5 .5 .5 .5 2 2 2 2 .5 .5 .5 .5 -2 -2;
-2.5 2.5 2.5 -2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 2.5 -2.5;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
DH2 = [1 0 0 0; 0 1 0 0; 0 0 1 -25; 0 0 0 1] * DH;
A = [0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1;
1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0;
0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0;
1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0;
0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0;
0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0;
0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0;
0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0;
0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0;
0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0;
0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0;
0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1;
0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0;
0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1;
1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0];


while r <= 2*pi
%T =  [1 0 0 tx; 0 1 0 ty; 0 0 1 tz; 0 0 0 1];
%S = [sx 0 0 0;0 sy 0 0;0 0 0 sz;0 0 0 1];
Rx = [1 cos(x) -sin(x) 0; 0 sin(x) cos(x) 0; 0 0 1 0; 0 0 0 1];
Ry = [cos(y) 0 sin(y) tx;0 1 0 ty;-sin(y) 0 cos(y) tz;0 0 0 1];
Rz = [cos(z) -sin(z) 0 0; sin(z) cos(z) 0 0; 0 0 1 0 ; 0 0 0 1];
P = [1 0 -b/d 0;0 1 -c/d 0 ;0 0 0 0;0 0 -1/d 1];
%DP = P*S*T*Rx*Ry*Rz*DH2;
S = [cos(r) 0 sin(r) tx;0 1 0 ty;-sin(r) 0 cos(r) tz;0 0 0 1];
DP = P*S*DH2;
DP1 = DP(1:3,:)./[DP(4,:);DP(4,:);DP(4,:)];
D2 = DP1(1:2,:);
D2T = transpose(D2);
gplot(A,D2T,'-')
axis ([-40 40,-20 20])
pause(.001)
r = r + (pi/48);
end
pause off

Edited by 4mad3u5

Share this post


Link to post
Share on other sites

This is my car randomly making a decision at every intersection which direction it whats to take around four buildings. I pushed the car off the origin and basically pushed the car's data points if I wanted it to go straight, if i wanted to do a rotation I did a rotation matrix.  

 

 

:


pause on
b = -40;           % x perspective view
c = 30;            % y perspective view
d = 80;            % z perspective view
x = 0;             % x theta
z = 0;             % z theta 
tx = 0;            % x location
ty = 0;            % y location
tz = 0;            % z location 
sx = 1;            % x scaling factor
sy = 1;            % y scaling facotr
sz = 1;            % z scaling facotr
n = 0;             % # of loops
inc = pi/12;       % theta rotaion inc
inc2 = 2.5;
pse = .001;        % pause delay 
wxmin = -60;
wxmax = 35;
wymin = -20;
wymax = 20;
tx1 =0;
ty1 = 0;
tz1 = 0;
tx2= 0;
ty2 = 0;
tz2 = 0;
tx3 = 0;
ty3 = 0;
tz3 = 0;


DP1 = [-6.5 -6.5 -6.5 -6.5 -2.5 -2.5 -.75 -.75 3.25 3.25  4.5 4.5  6.5 6.5 6.5    6.5   -0.75  -0.75 3.25  3.25        2      2;
          0    0  2.5  2.5  2.5  2.5    4    4    4    4  2.5 2.5  2.5 2.5   0      0    1.25   1.25 1.25  1.25     1.25   1.25;
       -2.5  2.5  2.5 -2.5 -2.5  2.5 -2.5  2.5 -2.5  2.5 -2.5 2.5 -2.5 2.5 2.5   -2.5    2.5   -2.5  2.5   -2.5       10    -10;
          1    1    1    1    1    1    1    1    1    1    1   1    1   1   1      1      1      1    1      1        1      1];

DP2 = [-5 5 5 -5 -5 5 5 -5; 0 0 0 0 10 10 10 10; 0 0 10 10 0 0 10 10; 1 1 1 1 1 1 1 1];

DP3 = [1 0 0 0; 0 1 0 0; 0 0 1 -40; 0 0 0 1] * DP2;
DP4 = [1 0 0 -30; 0 1 0 0; 0 0 1 -40; 0 0 0 1] * DP2;
DP5 = [1 0 0 -30; 0 1 0 0; 0 0 1 0; 0 0 0 1] * DP2;
Trans = [1 0 0 0; 0 1 0 0; 0 0 1 -15; 0 0 0 1] * DP1; % pushes DP1 off the origan 

DP6 = [5    6   7     8    9    10   11    12   13    14  15    16  17    18 19     20    20     20   20    20  20    20  20    20  20    20  20    20  20    20  20   20   -40  -41  -42 -43 -44 -45 -46 -47 -48 -49 -50 -50 -50 -50 -50  -50    -50      -50    -50    -50 -50      -50   -50      -50 -50      -50 -50      -50   -50   -50   -50 -50 ;
 0    0   0     0    0     0    0     0    0     0   0     0   0     0  0      0     0      0    0     0   0     0   0     0   0     0   0     0   0     0   0    0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0    0      0        0      0      0   0        0     0        0   0        0   0        0     0     0     0   0 ;
20 19.5  19  18.5   18  17.5   17  16.5   16  15.5  15  14.5  14  13.5 13   12.5   -40    -41  -42   -43 -45   -47 -49   -51 -53   -55 -55   -55 -55   -55 -55  -55   -55  -55  -55 -55 -55 -55 -55 -55 -55 -55 -55 -55 -55 -55 -55  -55     12     12.5     13   13.5  14     14.5    15     15.5  16     16.5  17     17.5  18.5    19  19.5  20;    
 1    1   1     1    1     1    1     1    1     1   1     1   1     1  1      1     1      1    1     1   1     1   1     1   1     1   1     1   1     1   1    1     1    1    1   1   1   1   1   1   1   1   1   1   1   1   1    1      1        1      1      1   1        1     1        1   1        1   1        1     1     1     1   1];

D = [
 0  1  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   1 ; 
 1  0  1  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ;  
 0  1  0  1   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  1  0   1  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  1   0  1  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   1  0  1  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  1  0  1  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  0  1  0  1  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  0  0  1  0  1  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  0  0  0  1  0  1 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  0  0  0  0  1  0 1   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  0  0  0  0  0  1 0   1  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  0  0  0  0  0  0 1   0  1  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  0  0  0  0  0  0 0   1  0  1  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  0  0  0  0  0  0 0   0  1  0  1    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  1  0    1    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  1    0    1     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    1    0     1   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    1     0   1   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     1   0   1   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;   
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   1   0   1   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;  
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   1   0   1   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   1   0   1   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;  
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   1   0   1   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;  
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   1   0   1   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   1   0   1   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   1   0   1   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   1   0   1   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   1   0   1   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0  ;
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   1   0   1   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   1   0   1     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0  ;
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   1   0     1    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   1     0    1    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     1    0    1   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    1    0   1   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;  
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    1   0   1   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   1   0   1   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0  ;
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   1   0   1   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   1   0   1   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;  
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   1   0   1   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;  
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   1   0   1   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;  
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   1   0   1   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;  
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   1   0   1   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   1   0   1   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0;  
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   1   0   1   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   1   0   1   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   1   0   1   0    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   1   0   1    0   0   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   1   0    1   0   0   0   0   0   0   0   0   0    0   0   0   0   0;  
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   1    0   1   0   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    1   0   1   0   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   1   0   1   0   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   1   0   1   0   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   1   0   1   0   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   1   0   1   0   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   1   0   1   0   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   1   0   1   0    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   1   0   1    0   0   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   1   0    1   0   0   0   0  ;
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   1    0   1   0   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    1   0   1   0   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   1   0   1   0 ; 
 0  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   1   0   1;
 1  0  0  0   0  0  0  0  0  0  0 0   0  0  0  0    0    0     0   0   0   0   0   0   0   0   0   0   0   0   0   0     0    0    0   0   0   0   0   0   0   0   0   0   0   0   0   0   0    0   0   0   0   0   0   0   0   0   0    0   0   0   1   0 ];
  

A = [0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0;
     1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0;
     0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
     1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
     0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0;
     0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0;
     1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0;
     0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1;
     0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0;
     0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1;
     0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0;
     0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0];
 
 
 
B = [0 1 0 1 1 0 0 0;
1 0 1 0 0 1 0 0;
0 1 0 1 0 0 1 0;
1 0 1 0 0 0 0 1;
1 0 0 0 0 1 0 1;
0 1 0 0 1 0 1 0;
0 0 1 0 0 1 0 1;
0 0 0 1 1 0 1 0];

Znew = zeros(8,22);
Znew1 = zeros(22,8);
Znew2 = zeros(8,8);
Znew3 = zeros(64,22);
Znew4 = zeros(64,8);
Znew5 = zeros(54,64);

Z3 = vertcat(A,Znew,Znew,Znew,Znew,Znew3);     
Z4 = vertcat(Znew1,B,Znew2,Znew2,Znew2,Znew4);           
Z5 = vertcat(Znew1,Znew2,B,Znew2,Znew2,Znew4);           
Z6 = vertcat(Znew1,Znew2,Znew2,B,Znew2,Znew4);         
Z7 = vertcat(Znew1,Znew2,Znew2,Znew2,B,Znew4);
Z8 = vertcat(Znew5,D);
Zall = horzcat(Z3,Z4,Z5,Z6,Z7,Z8) ;        %entire ajacinty martic

P = carPFunction(b,c,d);


decision = 1

while n < 10
   
    if decision == 1
       
        rand = 1
    
        if rand == 1 
             y =   0;
             tx1 = 0;
             tz1 = 0;
             tz2 = 30;
             tz3 = -30; 
             sx = 1;
            while y <= .5*pi
                      [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                      [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                        
                      y = y + inc;
            end
                decision = 2;
        end

        if rand == 2
             y =   0;
             tx1 = 0;
             tz1 = 0;
             tz2 = 0;
             tz3 = 0; 
             sx = 1;
            while y >= -.5*pi
                     [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                     [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                     
                     y = y - inc;
                 
            end
            decision = 3;
        end
        
        if rand == 3
             y =   0;
             tx1 = 0;
             tz1 = 0;
             tz2 = 0;
             tz3 = 0; 
             sx = 1;
            while tx1 >= -30
                    [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                    [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                    
                    tx1 = tx1 - inc2;
            end
            
                decision = 5;
        end   
    end
    
    
    if decision == 2
        rand = randi(2,1)
        
        if rand == 1 
             y = .5*pi;
             tx1 = 0;
             tz1 = 0;
             tz2 = 30;
             tz3 = -30;   
             sx = 1;
            while y <= 2*pi 
                [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
              
                y = y + inc;
            end
            n = n + 1
            decision = 1; 
        end

        if rand == 2
            y = .5*pi;
             tx1 = 30;
             tz1 = 0;
             tz2 = 30;
             tz3 = -30;   
             sx = -1;
            while y <= 2*pi 
                [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                y = y + inc;
            end
             decision = 4; 
        end
    end
    
    if decision == 3
        rand = randi(2,1)
       
        if rand == 1 
              y = -.5*pi;
              tx1 = 30;
              tz1 = 0;
              tz2 = 0;
              tz3 = 0; 
              sx = -1;
            while y >= -2*pi
                 [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                 [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                 y = y - inc;
            end
            
            decision = 4; 
     
        end

        if rand == 2
            y = -.5*pi;
              tx1 = 0;
              tz1 = 0;
              tz2 = 0;
              tz3 = 0; 
              sx = 1;
            while y >= -2*pi
                [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                y = y - inc;
            end
             decision = 1;
              n = n + 1
        end
    end
    
    if decision == 4
        rand = randi(3,1);
       
        if rand == 1 
            y = 0;
            tx1 = 30;
            tz1 = 0;
            tz2 = 0;
            tz3 = 0;
            sx = -1;
            
            while y >= -.5*pi
                [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                y = y - inc;
            end
            decision = 3; 
        end

        if rand == 2
            y = 0;
            tx1 = 30;
            tz1 = 0;
            tz2 = 30;
            tz3 = -30;
            sx = -1;
            
            while y <= .5*pi
                 [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                 [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                 y = y + inc;
            end
             decision = 2;
            
        end
        
          if rand == 3
             y =   0;
             tx1 = 30;
             tz1 = 0;
             tz2 = 0;
             tz3 = 0; 
             sx = -1;
            while tx1 >= 0
                     [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                     [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                     tx1 = tx1 - inc2;
            end
            
                decision = 8;
           end 
    end
    
     if decision == 5
        
         rand = randi(2,1)
        
        if rand == 1 
            y = 0;
            tx1 = -30;
            tz1 = 0;
            tz2 = 30;
            tz3 = -30;
            sx = 1; 
            while y <= 1.5*pi
                 [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                 [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                 y = y + inc;
            end
            
             decision = 6; 
        
        end

        if rand == 2
              y = 0;
              tx1 = -30;
              tz1 = 0;
              tz2 = 0;
              tz3 = 0; 
              sx = 1;
            while y >= -1.5*pi
                 [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                 [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                 y = y - inc;
            end
            decision = 7;
           
        end
     end
    
     
      if decision == 6
        rand = randi(3,1)
       
        if rand == 1 
            y = -.5*pi;
            tx1 = -30;
            tz1 = 0;
            tz2 = 30;
            tz3 = -30;
            sx= 1;
            while y <= 0
                [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                y = y + inc;
            end
             decision = 5;
             
        end

        if rand == 2
            y = -.5*pi;
            tx1 = 0;
            tz1 = 0;
            tz2 = 30;
            tz3 = -30;
            sx = -1;
            while y <= 0
                     [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                     [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                     y = y + inc;
            end
            
                decision = 8;
        end
        
          if rand == 3
             y   =   1.5*pi;
             tx1 = 0;
             tz1 = -30;
             tz2 = 0;
             tz3 = 0; 
             sx = 1;
            while tz1 <= 0
                     [DP ] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                     [D2T ] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                     tz1 = tz1 + inc2;
            end
            
               decision = 3;
          end 
      end
    
      
       if decision == 7
        rand = randi(3,1)
          
            if rand == 1 
                y   = .5*pi;     
                tx1 = 0;
                tz1 = 0;
                tz2 = 0;
                tz3 = 0;
                sx  = -1;
                while y >= 0
                            [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                            [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                            y = y - inc;
                end

                   decision = 8;
            end

            if rand == 2
                y   = .5*pi;
                tx1 = -30;
                tz1 = 0;
                tz2 = 0;
                tz3 = 0;
                sx  = 1;
                while y >= 0
                         [DP] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                         [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                         y = y - inc; 
                end
                decision = 5;

            end

            if rand == 3
                 y   = .5*pi;
                 tx1 = -30;
                 tz1 = 0;
                 tz2 = 0;
                 tz3 = 0; 
                 sx  = 1;
                while tz1 >= -30
                         [DP]  = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                         [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                         tz1 = tz1 - inc2;
                end

                decision = 2;

            end 
       end
       
       
       
       if decision == 8
       
           rand = randi(2,1)
       
            if rand == 1 
                y = 0;
                tx1 = 0;
                tz1 = 0;
                tz2 = 0;
                tz3 = 0;
                sx= -1;
                while y >= -1.5*pi
                     [DP]  = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                     [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                     y = y - (inc);   
                end
                decision = 7; 

            end

            if rand == 2
               y = 0;
               tx1 = 0;
               tz1 = 0;
               tz2 = 30;
               tz3 = -30;
               sx = -1;
                while y <= 1.5*pi
                         [DP]  = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans);
                         [D2T] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,DP, DP2, DP3, DP4,DP5,DP6,P);
                         y = y + (inc);
                end
                  decision = 6; 
            end
        end
end

pause off
    
    
    

you will also need carFunction1

 

:

function [DP ] = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans)
               
                T0  =  [1 0 0 tx1;
                        0 1 0 ty1; 
                        0 0 1 tz1; 
                        0 0 0   1];
                
                T1 =  [1 0 0 tx2; 
                       0 1 0 ty2;
                       0 0 1 tz2;
                       0 0 0   1];
                   
                T2 =  [1 0 0 tx3;
                       0 1 0 ty3; 
                       0 0 1 tz3; 
                       0 0 0   1];
                
                   
                S  =  [sx  0  0  0;
                       0   sy 0  0;
                       0   0  sz 0;
                       0   0  0  1];                        % Shear Matrix
                
                Rx = [    1       0       0  0;     
                          0   cos(x) -sin(x) 0;     
                          0   sin(x)  cos(x) 0; 
                          0       0       0  1];    % x Rotation matrix 
                
                Ry = [cos(y)      0  -sin(y) 0;     
                          0       1       0  0; 
                      sin(y)      0   cos(y) 0; 
                          0       0       0  1];     % y Rotation matrix

                Rz = [cos(z) -sin(z)      0  0; 
                      sin(z)  cos(z)      0  0; 
                          0       0       1  0; 
                          0       0       0  1];   % z Rotation matrix
   
                DP = S*T0*Rx*T2*Ry*T1*Rz*Trans;              

and carGUIFunction:

 

:

function [ D2T ] = carGUIFunction(pse,wxmin,wxmax,wymin,wymax,Zall,dCar0, dB0, dB1, dB2,dB3,dBoard0,P)               

                D3 = horzcat(dCar0, dB0, dB1, dB2,dB3,dBoard0);            
                Dpro = P * D3;  
                GP1 = Dpro(1:3,:)./[Dpro(4,:);Dpro(4,:);Dpro(4,:)];
                GP2 = GP1(1:2,:);
                D2T = transpose(GP2);
                gplot(Zall,D2T,'K')
                axis ([wxmin wxmax,wymin wymax])
                pause(pse)

And you will need the carPFunction

function [ P ] = carPFunction( b,c,d )

P  = [1 0 -b/d 0;0 1 -c/d 0 ;0 0 0 0;0 0 -1/d 1]; 


end

Edited by 4mad3u5

Share this post


Link to post
Share on other sites

I would like to be able to change the perspective view on it, be able to follow the car around. There are two views that I am very interested in: one, being able to look out the windshield and a dropped back overlook following the vehicle. Once I can do one I can do the other. 

Share this post


Link to post
Share on other sites

Final project: being able to move up or down a level and around building randomly while always being tangent to the line of any function you want to give to it. 

echo off
syms theta
pause on
b = -40;             % x perspective view
c =  40;             % y perspective view
d =  200;            % z perspective view

x = 0;             % x theta
z = 0;             % z theta 
sx = 1;            % x scaling factor
sy = 1;            % y scaling facotr
sz = 1;            % z scaling facotr

% wxmin = -60;
% wxmax =  90;
% wymin = -10;
% wymax =  20;

wxmin = -60;
wxmax =  90;
wymin = -40;
wymax =  30;


n = 0;             % # of loops
inc5 = 1; 
inc2 = 2.25;       % going forward increase
pse = .001;        % pause delay 

dCar = [-6.5 -6.5 -6.5 -6.5 -2.5 -2.5 -.75 -.75 3.25 3.25 4.5 4.5 6.5 6.5 6.5 6.5;
0 0 2.5 2.5 2.5 2.5 4 4 4 4 2.5 2.5 2.5 2.5 0 0;
-2.5 2.5 2.5 -2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 -2.5 2.5 2.5 -2.5;
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];

Trans = [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1] * dCar; % pushes DP1 off the origan 

height = 5;
dBuild = [-5 5 5 -5 -5 5 5 -5; 0 0 0 0 height height height height; 0 0 10 10 0 0 10 10; 
    1 1 1 1 1 1 1 1];

D = zeros(64,64);

A = [0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1;
     1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0;
     0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0;
     1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0;
     0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0;
     0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0;
     0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0;
     0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0;
     0 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0;
     0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0;
     0 0 0 0 0 0 0 0 1 0 0 1 1 0 0 0;
     0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0;
     0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1;
     0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0;
     0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1;
     1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0];

B = [0 1 0 1 1 0 0 0;
     1 0 1 0 0 1 0 0;
     0 1 0 1 0 0 1 0;
     1 0 1 0 0 0 0 1;
     1 0 0 0 0 1 0 1;
     0 1 0 0 1 0 1 0;
     0 0 1 0 0 1 0 1;
     0 0 0 1 1 0 1 0];

Znew = zeros(64,88);
Znew1 = zeros(64,8);
Znew2 = zeros(64,16);
Z = zeros(8,8);
Zhorz = horzcat(Z,Z); % 8 x 16
Zvert = vertcat(Z,Z); % 16 x 8
Znew3 = zeros(16,8);
Znew4 = zeros(16,64);
Znew5 = zeros(8,64);

Z3   = horzcat(A,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Zvert,Znew4);   %16 x 16, 16 x 8, 16 x 64 
Z4   = horzcat(Zhorz,B,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Z,Znew5);           % 8 x 16, 8 x 8, 8 x 64
Z5   = horzcat(Zhorz,Z,B,Z,Z,Z,Z,Z,Z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= 0;
tz2 = 0;
tz3 = 0;

% function1 = 4

array = 0;
y = pi;
row = 0;
col = .5;
sn  = 1;
dession = 0;


varx2=0;
varx3=0;
varx4=0;
varx5=0;
varx6=0;
varx8=0;
varx11=0;
varx12=0;
varx13=0;
varx14=0;
varx15=0;
varx17=0;
varx20=0;
varx21=0;
varx22=0;
varx23=0;
varx24=0;
varx26=0;
vary1=0;
vary2=0;
vary5=0;
vary6=0;
vary7=0;
vary8=0;
vary10=0;
vary11=0;
vary14=0;
vary15=0;
vary16=0;
vary17=0;
vary19=0;
vary20=0;
vary23=0;
vary24=0;
vary25=0;
vary26=0;

Y = zeros(8,8);


while n < 8
    dession = randi([0,3]);
    
    DP0 = [1 0 0          0; 0 1 0 0; 0 0 1         0; 0 0 0 1] * dBuild;
    DP1 = [1 0 0          0; 0 1 0 0; 0 0 1 -40*vary1; 0 0 0 1] * dBuild;
    DP2 = [1 0 0  -30*varx2; 0 1 0 0; 0 0 1 -40*vary2; 0 0 0 1] * dBuild;
    DP3 = [1 0 0  -30*varx3; 0 1 0 0; 0 0 1         0; 0 0 0 1] * dBuild;
    DP4 = [1 0 0   30*varx4; 0 1 0 0; 0 0 1         0; 0 0 0 1] * dBuild;
    DP5 = [1 0 0   30*varx5; 0 1 0 0; 0 0 1 -40*vary5; 0 0 0 1] * dBuild;
    DP6 = [1 0 0   30*varx6; 0 1 0 0; 0 0 1  40*vary6; 0 0 0 1] * dBuild;
    DP7 = [1 0 0          0; 0 1 0 0; 0 0 1  40*vary7; 0 0 0 1] * dBuild;
    DP8 = [1 0 0  -30*varx8; 0 1 0 0; 0 0 1  40*vary8; 0 0 0 1] * dBuild;
    
    DP9 = [1 0 0            0; 0 1 0 10; 0 0 1          0; 0 0 0 1] * dBuild;
    DP10 = [1 0 0           0; 0 1 0 10; 0 0 1 -40*vary10; 0 0 0 1] * dBuild;
    DP11 = [1 0 0  -30*varx11; 0 1 0 10; 0 0 1 -40*vary11; 0 0 0 1] * dBuild;
    DP12 = [1 0 0  -30*varx12; 0 1 0 10; 0 0 1          0; 0 0 0 1] * dBuild;
    DP13 = [1 0 0   30*varx13; 0 1 0 10; 0 0 1          0; 0 0 0 1] * dBuild;
    DP14 = [1 0 0   30*varx14; 0 1 0 10; 0 0 1 -40*vary14; 0 0 0 1] * dBuild;
    DP15 = [1 0 0   30*varx15; 0 1 0 10; 0 0 1  40*vary15; 0 0 0 1] * dBuild;
    DP16 = [1 0 0           0; 0 1 0 10; 0 0 1  40*vary16; 0 0 0 1] * dBuild;
    DP17 = [1 0 0  -30*varx17; 0 1 0 10; 0 0 1  40*vary17; 0 0 0 1] * dBuild;

    DP18 = [1 0 0           0; 0 1 0 -10; 0 0 1          0; 0 0 0 1] * dBuild;
    DP19 = [1 0 0           0; 0 1 0 -10; 0 0 1 -40*vary19; 0 0 0 1] * dBuild;
    DP20 = [1 0 0  -30*varx20; 0 1 0 -10; 0 0 1 -40*vary20; 0 0 0 1] * dBuild;
    DP21 = [1 0 0  -30*varx21; 0 1 0 -10; 0 0 1          0; 0 0 0 1] * dBuild;
    DP22 = [1 0 0   30*varx22; 0 1 0 -10; 0 0 1          0; 0 0 0 1] * dBuild;
    DP23 = [1 0 0   30*varx23; 0 1 0 -10; 0 0 1 -40*vary23; 0 0 0 1] * dBuild;
    DP24 = [1 0 0   30*varx24; 0 1 0 -10; 0 0 1  40*vary24; 0 0 0 1] * dBuild;
    DP25 = [1 0 0           0; 0 1 0 -10; 0 0 1  40*vary25; 0 0 0 1] * dBuild;
    DP26 = [1 0 0  -30*varx26; 0 1 0 -10; 0 0 1  40*vary26; 0 0 0 1] * dBuild;
    
    
   Dall=horzcat(DP0, DP1, DP2,DP3,DP4,DP5,DP6,DP7,DP8,DP9,DP10,DP11,DP12,DP13,DP14,DP15,DP16,DP17,DP18,DP19,DP20,DP21,DP22,DP23,DP24,DP25,DP26);
    
    
    
    if dession == 0
        ampx = 30;
        ampy = 20;
        inc5 = 1; 
        sn  = 2;
        vx =0;
        vz =5;
        
    end
    if dession == 1
        ampx = 15;
        ampy = 20;
        inc5 = 1; 
        sn  = 1;
        vx =15;
        vz =5;
        
    end
    if dession == 2
        ampx = 15;
        ampy = 20;
        inc5 = 1; 
        sn  = 1;
        vx =15;
        vz =5;
    end
    if dession == 3
        ampx = 15;
        ampy = 20;
        inc5 = 1; 
        sn  = 1;
        vx =15;
        vz =5;
    end
    if dession == 4
        ampx = 15;
        ampy = 20;
       
        sn  = 1;
        vx =15;
        vz =5;
    end
    if dession == 5
        ampx = 15;
        ampy = 20;
       
        sn  = 1;
        vx =15;
        vz =5;
    end
     if dession == 6
        ampx = 15;
        ampy = 20;
       
        sn  = 1;
        vx =15;
        vz =5;
    end
    if dession == 7
        ampx = 15;
        ampy = 20;
       
        sn  = 1;
        vx =15;
        vz =5;
    end
 
    f=[ampx*inc5*cos(theta);0;ampy*inc5*sin(sn * theta)];
    velocity=diff(f,theta,1);

    for newstep = 0 : pi/50 : 2*pi/1 
       
        if dession == 2
            ty1 =ty1 + pi/30;
%             dession = 3;
            if ty1 >= 20
                ty1 = -10;
            end
        end
        if dession == 3
            ty1 =ty1 + -pi/30;
%             dession = 3;
            if ty1 <= -20
                ty1 = 10;
            end
        end
        if dession == 4
            inc5 = inc5 + pi/50;
        end
        
        
        location=subs(f,theta,newstep);
        direction=subs(velocity,theta,newstep);
        y = pi+ atan2(direction(3,1),direction(1,1));
        tx1 = vx+location(1,1)-15;
        ty1 = ty1 + location(2,1);
        tz1 = vz+ location(3,1);
        DP = carFunction1(x,y,z,tx1,ty1,tz1,tx2,ty2,tz2,tx3,ty3,tz3,sx,sy,sz,Trans); 
        carFunction6(b,c,d,pse,wxmin,wxmax,wymin,wymax,DP,Dall,Zall);                   
    end
    n = n + 1;
    
    if dession > 4
        dession = 0;
    end
end
pause off

Share this post


Link to post
Share on other sites

That's... cool, I guess, but do you really need to post 8 times in a row?  The forums aren't your personal blog...

Share this post


Link to post
Share on other sites

Just showing all the things I have done with it. I guess I had a couple unnecessary posts. 

 

If anyone would like to expand this project with my I would love to do so. I am looking to get a better view, add a graphical layer to it, add a control engine, and a physics engine to it. I love programming 3D modeling and graphics programming and am looking for someone with the same passion. 

Edited by 4mad3u5

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!