plotting with a rectangle

3 vues (au cours des 30 derniers jours)
Burak Soydas
Burak Soydas le 25 Jan 2017
Commenté : dpb le 26 Jan 2017
Hey guys,
i am working on the simulation of a falling rectangle and have done the formulas. Now i need to test it so i need to plot it. As I need to see if the rotation is correct, I need to plot with a rectangle over my center of gravity. My project advisor told me to plot 4 points and connect them which I did. How can I put the centroid of the rectangle over the center of gravity of my simulation so that it moves with its coordinates and deegres?
my rectangle:
clear all
x1 = [-1 1]
y1 = [0.5 0.5]
plot(x1,y1,'b-');
hold on;
plot([1 1],[0.5, -0.5],'b-');
hold on;
plot([1 -1],[-0.5 -0.5],'b-');
hold on;
plot([-1 -1],[-0.5 0.5],'b-');
xlabel('x');
ylabel('y');
axis([-2 2 -2 2]);
I hope you get my question, if not feel free to ask and I try to explain it better.

Réponse acceptée

dpb
dpb le 25 Jan 2017
Modifié(e) : dpb le 25 Jan 2017
I'd approach it by using the COG and rotation as computed by the simulation and then a transformation from that to the location of a given vertex point is a simple matrix operation. Knowing that coordinate and given a width and height of the rectangle, using rectangle to make the drawing would then be "piece 'o cake!".
As sounds like homework/schoolwork problem, will leave with hints rather than actual code...
  3 commentaires
Burak Soydas
Burak Soydas le 26 Jan 2017
So I tried to use it like this:
rectangle('Position',[q 1 2]);
with q being the coordinates and the rotation computed. It has 3 rows and n colums with n beiing depentend of the time variable given at the beginning.
and it gives me this error: Error in klotz_run (line 20) reactangle('Position',[q 1 2]);
So what I want to do: I want a the position and the rotation of the rectangle for a time and then the next second and the next second and so on that it looks like a video of the rectangle falling on the ground
Is the problem that q has so many columns and it only needs one column?
dpb
dpb le 26 Jan 2017
What're the definitions of the elements of q for each time step?
I was presuming you were generating and plotting a step at a time rather than the full time history first then plotting--not that it really makes any difference excepting you need to address each column in a loop to do the latter...
Also I see there's an issue with rectangle -- I misread the doc and had simply presumed there just had to be a 'rotation' property in order for it to be a useful function. Unfortunately, TMW dropped the ball; it doesn't seem that you can do anything with it except change its aspect ratio, not its rotation.
patch will accept the four corners or as your instructor suggested, draw all four lines.
But, to address the coordinates of one time step at a time, use a loop and colon notation...
for i=1:size(q,2) % over each column in q
q(:,i) % are the elements of q for that timestep
...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by