{
"Find the Nearest Point" : {
"cat" : ["Geometry", "Analytic"],
"descr" : "A mastery game for high school",
"code" : [
"x,y=var('x,y')",
"html('In the boxes below, enter the point $(a,b)$ on the line $c\\,x + d\\,y=8$ that is nearest the origin.<br>You may change the line. But if the cell becomes inactive, please click the Evaluate button to restart.')",
"def make_num(c,default):",
" try:",
" result=QQ(c)",
" except:",
" try:",
" result=RR(c)",
" except:",
" print('Only integers or fractions allowed, instead of %r'%c)",
" return default",
" return result",
"def make_lin(c,default):",
" try:",
" result=QQ(c)",
" except:",
" try:",
" result=RR(c)",
" except:",
" print('Only integers or fractions allowed, instead of %r'%c)",
" return default",
" if result < 1 or result > 5:",
" print('c and d should be between 1 and 5')",
" return default",
" return result",
"def check(a,b,c,d):",
" msg=['Good job','Sorry. Try again. Or change c and d to change the line.']",
" i=1",
" if d*a==b*c and c*a+d*b==8:",
" i=0",
" return(msg[i])",
"@interact",
"def levelc(a='1/2',b='7/3',c='2',d='3'):",
" a=make_num(a,1/2)",
" b=make_num(b,7/3)",
" c=make_lin(c,2)",
" d=make_lin(d,3)",
" print(check(a,b,c,d))",
" q=implicit_plot(c*x+d*y== 8, (x,-1,5),(y,-1,5))",
" r=line([[0,0],[c,d]],linestyle='--',color='turquoise')",
" p=point([0,0],color='red')",
" p1=point([a,b],color='green',size=12)",
" html('Calculate the point $(a,b)$ on $f(x,y)='+str(c)+'\\,x + '+str(3)+'\\,y = 8$ which is nearest the origin.')",
" show(p1+p+q+r,aspect_ratio=1,axes=true,figsize=4)"
]
}
}