Combining two codes as one
古いコメントを表示
Hello Family,
Please I need to create three circles. Challenge One: Circle 1 is small and going round on the circumference of circle 2. Challenge 2: Circle 2 is nearly as big as circle 3. Circle 2 is the inner circle with close diameter with circle 3. Circle 2 is going round inside circle 3. I have the codes for challenge One and challenge Two individually...the problem is to make the two codes work as one.
Challenge One Codes:
r=18;
R=20;
radius=[r R]
velocity=[45 0]
colors=['c','r'] % This is to just make the points different colors
p=zeros(2,1); %here we will store the handles to delete the point
hold on
for i=1:2 %Loop to create multiple circles
th=0:pi/50:2*pi;
xunit=radius(i)*cos(th);
yunit=radius(i)*sin(th);
h=plot(xunit,yunit);
p(i)=plot(xunit(1),yunit(1),'o','MarkerFaceColor',colors(i),'Color',colors(i));
%creates a point on each graph
end
time=[0:0.001:100]; %time vector in seconds
for t=1:length(time)
for i=1:2 %Loop to create multiple circles
delete(p(i)); %delete the old point
%computes the new angle for each point as velocity*time
xunit=radius(i)*cos(velocity(i)*time(t));
yunit=radius(i)*sin(velocity(i)*time(t));
%creates a point on each graph
p(i)=plot(xunit(1),yunit(1),'o','MarkerFaceColor',colors(i),'Color',colors(i));
end
pause(0.01); %wait 0.01 seconds so the plot is displayed
end
hold off
Challenge Two Codes
t = linspace(0,5*pi );
x = cos(t );
y = sin(t );
plot(7*x,7*y)
axis equal
hold on
for t0 = t
h = plot(2*sin(t0),2*cos(t0),'or ','markersize',175);
pause(0.09 )
delete(h )
axis equal
end
5 件のコメント
dpb
2019 年 8 月 13 日
Is the tiny circle supposed to continue to orbit on the path of the inner of the two outer (which I presume represent the inner/outer casing diameters???)? What does it represent out there if that is so?
Or, is it supposed to be moving along boundary of the inner larger circle as the latter is moving inside the borehole? That's a more challenging geometry problem of translation of coordinate systems if so.
If the former, you should be able to just take the one line of code that plots the little one and put it in the loop of the second case to draw one then the other. You'll have to keep a second index to the precomputed position vector, or, probably better, just compute the position on the fly as well instead of using an array.
DARLINGTON ETAJE
2019 年 8 月 13 日
dpb
2019 年 8 月 13 日
Use the CODE button to format code...don't continue to expect others to do for you... :)
To solve the problem you need to read up on axes translation and global frames of reference versus reference frames. You have a global reference at the present for everything, what you need is to translate the position from the moving center of the inner from which you can define the location on its boundary to the fixed reference frame. With that,you can then determine the absolute coordinates of the tiny circle.
DARLINGTON ETAJE
2019 年 8 月 13 日
dpb
2019 年 8 月 13 日
But you don't have any code at all that does the definition of a reference frame nor translation. Just trying to graft these two independent pieces together won't cut it for the problem you're trying to solve.
You need to read up on the geometry and algebra of translation and rotation to get the basic ideas down first. There's quite a bit of pedgogical info on graphics and robotics translation that will introduce you to the basic idea.
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Assembly についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!