plotting with a rectangle
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
dpb
2017-1-25
编辑:dpb
2017-1-25
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 个评论
dpb
2017-1-26
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
...
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!