Lines: Point-Slope

Manipulate[
Module[{makegraph,gr,ptgr,grtck,b,usefractions,frac},

frac[val_]:=If[usefractions,Rationalize[val],val];

makegraph[usept_]:=Show[gr[usept],ptgr[usept],AxesStyle->Thick,BaseStyle->{14},AspectRatio->Automatic,
PlotRange->{{-6,6},{-6,6}},Ticks->{grtck,grtck},GridLinesStyle->GrayLevel[.2,.2],GridLines->{grtck,grtck},ImageSize->300,AxesOrigin->{0,0}];

gr[apt_]:=Plot[m*(x-apt[[1]])+apt[[2]],{x,-6,6},PlotStyle->{RGBColor[.49,0,0],Thick}];
ptgr[apt_]:=Graphics[{PointSize[0.03],RGBColor[.88,.63,.23],Point[{apt[[1]],apt[[2]]}]}];

DynamicModule[{usept=initpt},

grtck=Range[-5,5];
b[apt_]:=-m*apt[[1]]+apt[[2]];
usefractions=Switch[numbervals,allvals,False,fractionvals,True,integervals,True];

Column[{
Pane[Dynamic[Text[Switch[showeqn,show1,Style["",20],
show2,Style[Row[{Style["y",Italic],If[usept[[2]]<0," + "," - "],Abs[frac[usept[[2]]]]," = ",frac[m],"(",Style["x",Italic],If[usept[[1]]<0," + "," - "],Abs[frac[usept[[1]]]],")"}],20],
show3,Style[Row[{Style["y",Italic]," = ",TraditionalForm[If[m==0,If[b[usept]==0,"0",""],frac[m]]],If[m==0,"",If[b[usept]>0,Row[{Style["x",Italic]," + "}],Style["x ",Italic]]],TraditionalForm[If[b[usept]==0,"",frac[b[usept]]]]}],20]]]],ImageSize->{300,30},Alignment->Bottom],

LocatorPane[Dynamic[usept,
{usept=initpt,
(usept=Switch[numbervals,allvals,#,fractionvals,Round[#,0.5],integervals,Round[#]])&,
(usept=Switch[numbervals,allvals,#,fractionvals,Round[#,0.5],integervals,Round[#]])&;initpt=usept}],
Dynamic[makegraph[usept]], Appearance->Style[".",Opacity[0]]
]

},ItemSize->{Automatic,{3.75,Automatic}}]
]
],

{{showeqn,show2,""},{show1->"hide equation",show2->"point-slope form",show3->"slope-intercept form"},ControlType->RadioButtonBar,ControlPlacement->Left,Appearance->"Vertical"},
"",
{{numbervals,fractionvals,"          "},{integervals->"integer grid",fractionvals->"1/2 grid",allvals->"free points"},ControlType->RadioButtonBar,ControlPlacement->Left,Appearance->"Vertical"},

{{m,1.5,Style["slope",14]},-10,10,If[Switch[numbervals,allvals,False,fractionvals,True,integervals,True],1/12,0.001],ControlPlacement->Top},

{{initpt,{1,1},Style["●",Blue,14]},{-5,-5},{5,5},ControlType->None},

ControlPlacement->Left,RotateLabel->True,Initialization:>{frac[val_]:=If[usefractions,Rationalize[val],val];},TrackedSymbols:>{m,showeqn,initpt},AutorunSequencing->{1,3,4}]

THIS NOTEBOOK IS THE SOURCE CODE FROM

"Lines: Point-Slope" from The Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/LinesPointSlope/

Contributed by: Abby Brown

A full-function Wolfram Mathematica 6 system is required to edit this notebook.
GET WOLFRAM MATHEMATICA 6 »

© The Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »