I'm using an old spirograph script. Remember spirographs? The little circle inside traces a figure inside the bigger circle. Yeah, it's like that.
So I'm trying to change the stationary figure from a circle into the shape of a high-school-track. Let me explain.
This is what I started out with:
This is what I want to have:
So I created my own script that draws the track shape by connecting two semicircles with two line segments. The code I have posted below begins with the plotting of the track.
Here's my code:
function frame2(a,b)
theta=0;
while 1
t = linspace(pi/2, 3*pi/2, 512);
x = a*cos(t)- 2;
y = a* sin(t);
plot(x,y,'k');
hold on;
t = linspace(-pi/2, pi/2, 512);
x = a*cos(t) + 2;
y = a*sin(t);
plot(x,y,'k');
hold on;
t=linspace(-2,2,512);
x = t;
y = 0*t + a;
plot(x,y,'k');
t=linspace(-2,2,512);
x = t;
y = 0*t - a;
plot(x,y,'k');
hold on;
t=linspace(0,2*pi,512);
x = b * cos(t)+ (a + b) * cos(theta);
y = b * sin(t)+ (a + b) * sin(theta);
plot(x,y,'b');
x = (a + b) * cos(theta) - b * cos((a + b) * theta / b);
y = (a + b) * sin(theta) - b * sin((a + b) * theta / b);
plot(x, y, 'kO');
x = t/(2*pi) * (a + b) * cos(theta);
y = t/(2*pi)* (a + b) * sin(theta);
plot(x, y, 'k');
x = (1-t/(2*pi))* (a + b) * cos(theta)+(t/(2*pi)) * ((a+b) * cos(theta) - b * cos((a+b) * theta / b));
y = (1-t/(2*pi))* (a + b) * sin(theta)+(t/(2*pi)) * ((a+b) * sin(theta) - b * sin((a+b) * theta / b));
plot(x, y, 'k');
if a>1
axis([-3*a, 3*a, -3*a, 3*a]);
elseif a<=1
axis([-4, 4, -4, 4]);
end
s = linspace(0, theta, 2024);
x = (a + b) * cos(s) - b * cos((a + b) * s / b);
y = (a + b) * sin(s) - b * sin((a + b) * s / b);
plot(x, y, 'r');
theta = theta + pi / 78;
hold off;
pause(0.03);
if theta > 180
theta = 0;
end
end
end
If you run this in your command window, you will see that the track is intact, but the small rolling circle rolls on the outside of an invisible stationary circle. This is because I have not altered the equations of the small rolling circle nor any of the equations for everything else that follows it.
So modifying the equations for the small, rolling circle seems fairly simple at first. To modify for the left and right semicircle of the track, I suggest this:
t=linspace(0,2*pi,512);
if and(t>pi/2,t<3*pi/2)
x = b * cos(t)+ (a + b) * cos(theta);
y = b * sin(t)+ (a + b) * sin(theta);
elseif and(t>-pi/2,t<pi/2)
x = b * cos(t)+ (a + b) * cos(theta);
y = b * sin(t)+ (a + b) * sin(theta);
end
but then my problem comes when I try to figure out how to get equations for the rolling circle when it's on the straightaways on the track. What value of t is that valid for? I cannot comprehend it because the linspace going from 0 to 2*pi only works when working strictly with circles.
And also, I want to mention that I do not want to use fplot or the piecewise command or anything that involves symbolic variables. The spirograph works great on its own without symbolic variables so I think this is doable. How do I turn the stationary circle into a stationary high-school-track?