plot a 2D triangle with three equilateral sides which starts being centered at location (0,0)
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Tony Nguyen
 el 19 de Oct. de 2017
  
The objective of this project is to plot a 2D triangle with three equal sides of length 2, which starts by being centered at location (0,0), and continuously moves within a square area which is limited between -10 to 10 horizontally and -10 to 10 vertically. The center of the triangle should never exit this 20 x 20 square area. In other words, when the center of the triangle reaches those limits, the triangle should bounce back so that it stays within the 20 x 20 box. At the same time, the triangle should be rotating about its center. You may choose the speed with which the triangle moves, and the speed with which the triangle rotates around its center yourselves. However, the triangle should not be moving just horizontally or just vertically. Also, it should not be moving with the same speed horizontally and vertically.
Below is my code
% PROJECT 1 clc clear all close all
%c=(0,0) xo=[-1 1 0 -1] yo=[-1 -1 1 -1]
% The following two lines rotate the point (xo,yo) % around (0,0) by angle pi/10.
for i=0:0.1:5
    x1=xo*cos(pi/10)+yo*sin(pi/10);
    y1=-xo*sin(pi/10)+yo*cos(pi/10);
    xo=x1;
    yo=y1;
    xo=xo+i;
    yo=yo+i;
% Set the limits of the axes between xmin and xmax % horizontally between ymin and ymax vertically. % Plot
figure(1),plot(x1,y1); set(gca,'xlim',[-10 10],'ylim',[-10 10]);
% Pause function is used to slow down the animation. pause(0.25) end
I've gotten it to move, but not quite the project asks for.
Please help thanks!
0 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
				Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

