Arc Length of a 3D Curve
Carl Runco & Daniel Charles
253 Honors Spring 2009
restart:
with(Maplets[Elements]):with(Maplets[Tools]):with(plots):
StartEngine();
randomize():
lightorange:="#FFB300":
lightcyan:="#DDFFFF":
lightblue:="#CFCFFF":
lightgreen:="#CCFFCC":
darkgreen:="#00C000":
ColorBkgd:=wheat:
ColorFooter:=lightcyan:
ColorNewButton:=magenta: # or Make, Save, Enter Problem
ColorReturnButton:=magenta:
ColorCloseButton:=pink: # or Quit, Clear, Reset, Cancel
ColorHintButton:=lightorange: # or Syntax
ColorPrevButton:=turquoise: # or Update
ColorEnterButton:=turquoise:
ColorSimplifyButton:=lightorange:
ColorCheckButton:=green:
ColorShowButton:=lightorange:
ColorPlotButton:=tan: ColorPlotButtonFrgd:=black:
ColorTableBkgd:=lightgreen:
ColorCalculatorBkgd:=gold:
ColorMessage:=white: ColorMessageFrgd:=black:
ColorInput:=turquoise: ColorInputFrgd:=black:
ColorCorrect:=green: ColorCorrectFrgd:=black:
ColorIncorrect:=red: ColorIncorrectFrgd:=white:
ColorWarning:=yellow: ColorWarningFrgd:=black:
ColorShow:=lightorange: ColorShowFrgd:=black:
ColorHint:=lightorange: ColorHintFrgd:=black: # or Info, Syntax
ColorDisable:=wheat: ColorDisableFrgd:=black:
FontFooter:=Font("helvetica",10):
FontSymbol:=Font("symbol",12):
FontBig:=Font("times",24):
First:=true:
formCURVE:=[
[a, b, r, r*cos(t), r*sin(t), t, [a,[i*Pi $i=-2..1]], [b,[i*Pi $i=-1..2]], [r, [$1..9]]],
#[a, b, r, ln(t), r*t, sqrt(8*r*t), [a,[$1..9]], [b,[$1..9]], [r, [$1..9]]],
NULL]:
randform:=rand(1..nops(formCURVE)):
start:="":
finish:="":
crv:="":
emptyplot:=plot3d(0, x = -3..3, y=-3..3, view=-3..3, axes=normal, labels=["","",""], grid=[2,2], color=white, scaling=constrained):
RandomProblem:=proc()
global formCURVE, randform, start, finish, crv, C;
local RandCURVE, i, pname, pvals;
RandCURVE:=formCURVE[randform()];
do
C:=RandCURVE[1..8];
for i from 7 to nops(RandCURVE) do
pname:=RandCURVE[i,1];
pvals:=RandCURVE[i,2];
C:=eval( C, pname=pvals[rand(1..nops(pvals))()] );
end do;
if C[1]<>C[2] then
start,finish:=sort(C[1..2], (a,b)->evalf(a)<evalf(b))[];
crv:=[C[4], C[5], C[6]];
return;
end if;
end do;
end proc:
TEXTprob1:=
" Find the arc length of the curve r(t) = ( %a , %a , %a ) from t = %a to t = %a.":
NewProblem:=proc()
global First, start, finish, crv, form, arclen, template, velocity, valueR;
local integrand;
Set(reply="Please wait while the graph is drawn.",
reply(background)=ColorWarning, reply(foreground)=ColorWarningFrgd);
Set(APlot=emptyplot);
if First then
First:=false;
Set(TFvelocity(enabled)=true, TFvelocity(background)=ColorInput);
Set(Bvelck(enabled)=true, Bvelck(background)=ColorCheckButton);
Set(Bvelsh(enabled)=true, Bvelsh(background)=ColorHintButton);
end if;
Set(Bvalck(enabled)=false, Bvalck(background)=ColorDisable);
Set(Bvalsh(enabled)=false, Bvalsh(background)=ColorDisable);
Set(Bformck(enabled)=false, Bformck(background)=ColorDisable);
Set(Bformsh(enabled)=false, Bformsh(background)=ColorDisable);
Set(Barclenck(enabled)=false, Barclenck(background)=ColorDisable);
Set(Barclensh(enabled)=false, Barclensh(background)=ColorDisable);
Set(TFvalue(enabled)=true, TFvalue(background)=ColorDisable);
Set(TFvelocity(enabled)=true, TFvelocity(background)=ColorInput);
Set(problem=sprintf(TEXTprob1, crv[1], crv[2], crv[3], start, finish));
Set(TFform=" Int(|r'(t)|, t=a..b) ");
Set(TFvelocity="[ dx, dy, dz]");
Set(TFvalue="");
Set(TFval="", TFval(background)=ColorMessage, TFval(foreground)=ColorMessageFrgd);
Set(TFform(enabled)=false, TFform(background)=ColorDisable);
Set(formck="",
formck(background)=ColorMessage, formck(foreground)=ColorMessageFrgd):
Set(TFarclen="",
TFarclen(enabled)=false, TFarclen(background)=ColorDisable);
Set(arclenck="",
arclenck(background)=ColorMessage, arclenck(foreground)=ColorMessageFrgd):
Set(MMLform=MathML[Export](L = Int("|r'(t)|",t=a..b)));
Set(TFvel="", TFvel(enabled)=true,
TFvel(background)=ColorMessage, TFvel(foreground)=ColorMessageFrgd);
integrand:=sqrt((cat(d,x)/cat(d,t))^2+(cat(d,y)/cat(d,t))^2+(cat(d,z)/cat(d,t))^2);
template:=Int(integrand,var=a..b);
integrand:=simplify(sqrt(diff(crv[1],t)^2+diff(crv[2],t)^2+diff(crv[3],t)^2));
form:=Int( integrand, t=start..finish );
arclen:=value(form);
velocity:=[diff(crv[1],t),diff(crv[2],t),diff(crv[3],t)];
valueR:=simplify(sqrt(diff(crv[1],t)^2+diff(crv[2],t)^2+diff(crv[3],t)^2));
Set(APlot=spacecurve([crv[1],crv[2],crv[3]], t=start..finish, axes=normal, scaling=constrained));
Set(reply="Finished",
reply(background)=ColorHint, reply(foreground)=ColorHintFrgd);
end proc:
Check_vel:=proc()
global velocity;
local user_vel, message;
message:="";
if Get(TFvelocity)="" then
Set(reply=" You must enter an expression to be checked.",
reply(background)=ColorWarning, reply(foreground)=ColorWarningFrgd);
return;
end if;
user_vel:=Get(TFvelocity::list, corrections=true, update=true):
if velocity <> user_vel then
Set(TFvel="Incorrect",
TFvel(background)=ColorIncorrect, TFvel(foreground)=ColorIncorrectFrgd):
message:="Sorry.":
Set(reply=cat(message, " Try again."),
reply(background)=ColorIncorrect, reply(foreground)=ColorIncorrectFrgd):
else
Set(TFvel="Correct.",
TFvel(background)=ColorCorrect, TFvel(foreground)=ColorCorrectFrgd):
Set(reply="Awesome! You got it right!",
reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd):
end if;
if message<>"" then
Set(TFvalue="",
TFvalue(enabled)=false, TFvalue(background)=ColorDisable);
Set(Bvalck(enabled)=false, Bvalck(background)=ColorDisable);
Set(TFval="",
TFval(enabled)=false, TFval(background)=ColorDisable);
Set(Bvalsh(enabled)=false, Bvalsh(background)=ColorDisable);
Set(TFvel="Incorrect",
TFvel(background)=ColorIncorrect, TFvel(foreground)=ColorIncorrectFrgd):
Set(reply=cat(message, "Try again."),
reply(background)=ColorIncorrect, reply(foreground)=ColorIncorrectFrgd):
else
Set(TFvalue(enabled)=true, TFvalue(background)=ColorInput);
Set(Bvalck(enabled)=true, Bvalck(background)=ColorCheckButton);
Set(TFval="", TFval(enabled)=true,
TFval(background)=ColorMessage, TFval(foreground)=ColorMessageFrgd);
Set(Bvalsh(enabled)=true, Bvalsh(background)=ColorShowButton);
Set(TFvel="Correct",
TFvel(background)=ColorCorrect, TFvel(foreground)=ColorCorrectFrgd):
Set(reply="Great! Now finish it up!",
reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd):
end if;
end proc:
Show_vel:=proc()
global velocity, lightorange;
Set(TFvelocity=velocity):
Set(TFvel="Shown",
TFvel(background)=ColorShow, TFvel(foreground)=ColorShowFrgd):
Set(reply="Try the next steps on your own.",
reply(background)=ColorShow, reply(foreground)=ColorShowFrgd):
Set(TFvalue(enabled)=true, TFvalue(background)=ColorInput);
Set(Bvalck(enabled)=true, Bvalck(background)=ColorCheckButton);
Set(TFval="", TFval(enabled)=true,
TFval(background)=ColorMessage, TFval(foreground)=ColorMessageFrgd);
Set(Bvalsh(enabled)=true, Bvalsh(background)=ColorShowButton);
end proc:
Check_val:=proc()
global valueR;
local user_val, message;
message:="";
if Get(TFvalue)="" then
Set(reply=" You must enter an expression to be checked.",
reply(background)=ColorWarning, reply(foreground)=ColorWarningFrgd);
return;
end if;
user_val:=Get(TFvalue::realcons, corrections=true, update=true):
if valueR <> user_val then
Set(TFval="Incorrect",
TFval(background)=ColorIncorrect, TFval(foreground)=ColorIncorrectFrgd):
message:="Sorry.":
Set(reply=cat(message, " Try again."),
reply(background)=ColorIncorrect, reply(foreground)=ColorIncorrectFrgd):
else
Set(TFval="Correct.",
TFval(background)=ColorCorrect, TFval(foreground)=ColorCorrectFrgd):
Set(reply="Awesome! You got it right!",
reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd):
end if;
if message<>"" then
Set(TFform(enabled)=false, TFform(background)=ColorDisable);
Set(Bformck(enabled)=false, Bformck(background)=ColorDisable);
Set(formck="",
formck(enabled)=false, formck(background)=ColorDisable);
Set(Bformsh(enabled)=false, Bformsh(background)=ColorDisable);
Set(TFval="Incorrect",
TFval(background)=ColorIncorrect, TFval(foreground)=ColorIncorrectFrgd):
Set(reply=cat(message, "Try again."),
reply(background)=ColorIncorrect, reply(foreground)=ColorIncorrectFrgd):
else
Set(TFform(enabled)=true, TFvalue(background)=ColorInput);
Set(Bformck(enabled)=true, Bformck(background)=ColorCheckButton);
Set(formck="", formck(enabled)=true,
formck(background)=ColorMessage, formck(foreground)=ColorMessageFrgd);
Set(Bformsh(enabled)=true, Bformsh(background)=ColorShowButton);
Set(TFval="Correct",
TFval(background)=ColorCorrect, TFval(foreground)=ColorCorrectFrgd):
Set(reply="Way to go! Keep it up!",
reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd):
end if;
end proc:
Show_val:=proc()
global valueR, lightorange;
Set(TFvalue=valueR):
Set(TFval="Shown",
TFval(background)=ColorShow, TFval(foreground)=ColorShowFrgd):
Set(reply="I know you can do the rest.",
reply(background)=ColorShow, reply(foreground)=ColorShowFrgd):
Set(TFform(enabled)=true, TFform(background)=ColorInput);
Set(Bformck(enabled)=true, Bformck(background)=ColorCheckButton);
Set(formck="", formck(enabled)=true,
formck(background)=ColorMessage, formck(foreground)=ColorMessageFrgd);
Set(Bformsh(enabled)=true, Bformsh(background)=ColorShowButton);
end proc:
Check_form:=proc()
global form;
local dom, f, user_dom, user_f, user_form, message;
if Get(TFform)="" then
Set(reply="Nothing to Check",
reply(background)=ColorWarning, reply(foreground)=ColorWarningFrgd);
return;
end if;
user_form:=Get(TFform::anything, corrections=true, update=true):
Set(MMLform=MathML[Export](L=user_form)):
message:="";
if not member(op(0,user_form),{int,Int}) then
message:=cat(message, " This response must be a definite integral. (You can use either Int or int.)");
else
f,dom:=op(form);
user_f,user_dom:=op(user_form);
if lhs(dom)<>lhs(user_dom) then
message:=cat(message, " The arc length integral has the wrong integration variable.")
end if;
if rhs(dom)<>rhs(user_dom) then
message:=cat(message, " The limits of integration on the arc length integral are not correct.")
end if;
if simplify(normal(f-user_f))<>0 assuming lhs(dom)>op(1,rhs(dom)), lhs(dom)<op(2,rhs(dom)) then
message:=cat(message, " The integrand of the arc length integral is incorrect.")
end if;
end if;
if message<>"" then
Set(TFarclen="",
TFarclen(enabled)=false, TFarclen(background)=ColorDisable);
Set(Barclenck(enabled)=false, Barclenck(background)=ColorDisable);
Set(arclenck="",
arclenck(enabled)=false, arclenck(background)=ColorDisable);
Set(Barclensh(enabled)=false, Barclensh(background)=ColorDisable);
Set(formck="Incorrect",
formck(background)=ColorIncorrect, formck(foreground)=ColorIncorrectFrgd):
Set(reply=cat(message, "Try again."),
reply(background)=ColorIncorrect, reply(foreground)=ColorIncorrectFrgd):
else
Set(TFarclen(enabled)=true, TFarclen(background)=ColorInput);
Set(Barclenck(enabled)=true, Barclenck(background)=ColorCheckButton);
Set(arclenck="", arclenck(enabled)=true,
arclenck(background)=ColorMessage, arclenck(foreground)=ColorMessageFrgd);
Set(Barclensh(enabled)=true, Barclensh(background)=ColorShowButton);
Set(formck="Correct",
formck(background)=ColorCorrect, formck(foreground)=ColorCorrectFrgd):
Set(reply="Great! Now finish it up!",
reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd):
end if;
end proc:
Show_form:=proc()
global form, lightorange;
Set(TFform=form):
Set(MMLform=MathML[Export](L=form)):
Set(TFarclen(enabled)=true, TFarclen(background)=ColorInput);
Set(Barclenck(enabled)=true, Barclenck(background)=ColorCheckButton);
Set(Barclensh(enabled)=true, Barclensh(background)=ColorShowButton);
Set(formck="Shown",
formck(background)=ColorShow, formck(foreground)=ColorShowFrgd):
Set(reply="Next time try it yourself.",
reply(background)=ColorShow, reply(foreground)=ColorShowFrgd):
end proc:
Check_arclen:=proc()
global arclen;
local user_arclen;
if Get(TFarclen)="" then
Set(reply=" You must enter an expression to be checked.",
reply(background)=ColorWarning, reply(foreground)=ColorWarningFrgd);
return;
end if;
user_arclen:=Get(TFarclen::realcons, corrections=true, update=true):
if simplify(normal(arclen - user_arclen))<> 0 then
Set(arclenck="Incorrect",
arclenck(background)=ColorIncorrect, arclenck(foreground)=ColorIncorrectFrgd):
Set(reply=cat("Sorry.", " Try again."),
reply(background)=ColorIncorrect, reply(foreground)=ColorIncorrectFrgd):
else
Set(arclenck="Correct.",
arclenck(background)=ColorCorrect, arclenck(foreground)=ColorCorrectFrgd):
Set(reply="Awesome! You got it right!",
reply(background)=ColorCorrect, reply(foreground)=ColorCorrectFrgd):
end if;
end proc:
Show_arclen:=proc()
global arclen, lightorange;
Set(TFarclen=arclen):
Set(arclenck="Shown",
arclenck(background)=ColorShow, arclenck(foreground)=ColorShowFrgd):
Set(reply=" So that was practice. Try doing it yourself.",
reply(background)=ColorShow, reply(foreground)=ColorShowFrgd):
end proc:
Arc_Length:=Maplet(onstartup=RunWindow(MAIN),
Font[helv10]("helvetica",10),
Window[MAIN]( title="3D Arc Length", defaultbutton=Bnew,
[ halign=none, inset=0, spacing=0, background=ColorBkgd,
[ background=ColorBkgd,
Button[Bnew]("New Problem", onclick=ANewProblem, background=ColorNewButton),
HorizontalGlue(),
Button("Quit", Shutdown(), background=ColorCloseButton)
],
[ background=ColorBkgd,
TextBox[problem]("Please click New Problem to begin.",
width=100, height=2, editable=false, background=ColorMessage)
],
[ background=ColorBkgd,
[ border=true, inset=0, spacing=0, background=ColorBkgd,
caption="Graph",
[ background=ColorBkgd
],
Plotter[APlot](value=emptyplot,
width=350, height=350)
],
[ halign=none, background=ColorBkgd, inset=0, spacing=0,
BoxColumn( background=ColorBkgd, inset=0, spacing=0, border=true,
caption="Step 1: Find r'(t), or the velocity of the function.",
[ background=ColorBkgd,
"r'(t) =",
TextField[TFvelocity](width=20,
enabled=false, background=ColorDisable),
HorizontalGlue(),
Button[Bvelck]("Check", Evaluate(function="Check_vel"),
enabled=false, background=ColorDisable),
TextField[TFvel](width=7,
editable=false, background=ColorMessage),
Button[Bvelsh]("Show", Evaluate(function="Show_vel"),
enabled=false, background=ColorDisable),
HorizontalGlue()
]
),
BoxColumn( background=ColorBkgd, inset=0, spacing=0, border=true,
caption="Step 2: Find the length of r'(t).",
[ background=ColorBkgd,
"|r'(t)| =",
TextField[TFvalue](width=20,
enabled=false, background=ColorDisable),
HorizontalGlue(),
Button[Bvalck]("Check", Evaluate(function="Check_val"),
enabled=false, background=ColorDisable),
TextField[TFval](width=7,
editable=false, background=ColorMessage),
Button[Bvalsh]("Show", Evaluate(function="Show_val"),
enabled=false, background=ColorDisable),
HorizontalGlue()
]
),
BoxColumn(background=ColorBkgd, inset=0, spacing=0, border=true,
caption="Step 3: Setup the integral for the arc length.",
[ background=ColorBkgd,
"L =",
TextField[TFform]("Int( |r'(t)| ,t=a..b)", width=30,
enabled=false, background=ColorDisable)
],
[ background=ColorBkgd,
MathMLViewer[MMLform](value=MathML[Export](L = Int("|r'(t)|",t=a..b)), width=300, height=100)
],
[ background=ColorBkgd,
HorizontalGlue(),
Button[Bformck]("Check", Evaluate(function="Check_form"),
enabled=false, background=ColorDisable),
TextField[formck](width=6,
editable=false, background=ColorMessage),
Button[Bformsh]("Show", Evaluate(function="Show_form"),
enabled=false, background=ColorDisable),
HorizontalGlue()
]
),
BoxColumn( background=ColorBkgd, inset=0, spacing=0, border=true,
caption="Step 4: Evaluate the integral to find the arc length.",
[ background=ColorBkgd,
"L =",
TextField[TFarclen](width=20,
enabled=false, background=ColorDisable),
HorizontalGlue(),
Button[Barclenck]("Check", Evaluate(function="Check_arclen"),
enabled=false, background=ColorDisable),
TextField[arclenck](width=6,
editable=false, background=ColorMessage),
Button[Barclensh]("Show", Evaluate(function="Show_arclen"),
enabled=false, background=ColorDisable),
HorizontalGlue()
]
)
]
],
[ background=ColorBkgd,
TextBox[reply](width=40, height=3, editable=false, background=ColorMessage),
Label(Image(Logo)),
Label(Image(LIBLogo))
],
[ background="#DDFFFF", inset=0, spacing=0,
Label("Programmers: Carl Runco & Daniel Charles", font=helv10),
HorizontalGlue(),
Label("Copyright P. Yasskin 2009", font=helv10)
]
]),
Action[ANewProblem](
Evaluate(function="RandomProblem"),
Evaluate(function="NewProblem")
)
):
First:=true:
Maplets[Display]( Arc_Length );