Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Help with MatLab coding needed

  • 29-07-2010 03:41PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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,590 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