Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help with MatLab coding needed

Options
  • 29-07-2010 3:41pm
    #1
    Registered Users Posts: 61 ✭✭


    Hey guys was wondering if you could help, I am working on a thesis at the moment and I need a bit of help with some coding issues.

    I am trying to get a wheel(a point) to move along a road profile. I have a road profile(which is basically a plotted line) already provide, which is 10 meters long, I just cant figure out how to get the wheel to move along the road profile.

    I know the solution is staring me in the face but have you guys got any solutions?

    Thanks!


Comments

  • Hosted Moderators Posts: 7,486 ✭✭✭Red Alert


    Are you trying to make a video of it, basically the wheel rolls along the road?


  • Registered Users Posts: 61 ✭✭[DM]Frink


    Yeah thats pretty much what im trying to do, im trying to get a bus to move along, but if I can get a wheel to move im sure I can figure out the rest. Have you any ideas?


  • Moderators, Arts Moderators Posts: 10,518 Mod ✭✭✭✭5uspect


    Probably dragging up an old thread but here is a quick way to do that.
    R = 1; % Radius
    
    % x and y positons of the curve
    x = linspace(0,2*pi,1000);
    y = sin(x);
    
    % Create a plot
    plot(x,y)
    xlim([0 2*pi])
    ylim([-2 2])
    
    for m = 1:3
        % Play three times
        for n = 1:length(x)
            X = x(n); % Current value of x
            Y = y(n); % Current value of y
    
            % Correct for radius, need to determind curve normals for correct
            % positioning!
            X = X-R/2;
            Y = Y-R/2;
            
            % draw a circle
            r1 = rectangle('Position',[X,Y,R,R],'Curvature',[1,1],...
            'FaceColor','r');
    
            daspect([1,1,1]) % fix aspect ratio
            drawnow % Update the plot
            delete(r1) %remove the wheel for the next pass of the loop
        end
    end
    

    You'll need to figure out a parallel curve of your path offset by the radius so that the circle appears to roll along the surface. Someone else has already written one so I won't do it here.

    If you want to make the wheel rotate use patch instead of rectangle and add a suitable texture.


Advertisement