3
$\begingroup$

In the, somewhat basic, code below I would like to learn how to replace the g2, g5 and g8 lines with a shorter command. I've made use of one parameter #1 but how do I make use of a second to vary the .2, .5, and .8 values? Perhaps there are other modifications to the code that you suggest to make it better and more ”general” and flexible. TIA.

L = 10;
y[x_] := Sqrt[L^2 - x^2]
gr1 = Graphics[Line[{{10 - #1, 0}, {0, y[10 - #1]}}] & /@ Range[0, 10, .125]];
p2 = {10 - #1, 0} + ({0, y[10 - #1]} - {10 - #1, 0})*.2 & /@ Range[0, 10, .125];
p5 = {10 - #1, 0} + ({0, y[10 - #1]} - {10 - #1, 0})*.5 & /@ Range[0, 10, .125];
p8 = {10 - #1, 0} + ({0, y[10 - #1]} - {10 - #1, 0})*.8 & /@ Range[0, 10, .125];
gr2 = Graphics[{Red, Point[p2]}];
gr5 = Graphics[{Red, Point[p5]}];
gr8 = Graphics[{Red, Point[p8]}];
Show[gr1, gr2, gr5, gr8]
$\endgroup$
5
$\begingroup$
linecoords = {{#, 0}, {0, y[#]}} & /@ (10 - Range[0, 10, .125]);
pointcoords = Table[lc[[1]] (1 - i) + i lc[[2]], {lc, linecoords}, {i, {.2, .5, .8}}];

Graphics[{Line[linecoords], Red, Point /@ pointcoords}]

enter image description here

$\endgroup$
5
$\begingroup$
L = 10;
y[x_] := Sqrt[L^2 - x^2];
Graphics[{Table[
   Line[{{10 - i, 0}, {0, y[10 - i]}}], {i, 0, 10, .125}], Red, 
  Table[Point[{10 - i, 0} + ({0, y[10 - i]} - {10 - i, 0})*j], {i, 0, 
    10, .125}, {j, {.2, .5, .8}}]}]

enter image description here

$\endgroup$
1
  • $\begingroup$ y[x_] := Sqrt[L^2 - x^2]; f[x_, t_] := {10 - x, 0} + t*({0, y[10 - x]} - {10 - x, 0}); {ParametricPlot[f[x, t], {x, 0, 10}, {t, 0, 1}, MeshFunctions -> (#3 &), Mesh -> {Range[0, 10, .125]}, MeshStyle -> Black, PlotStyle -> None], ParametricPlot[{Table[f[x, t], {t, {.2, .5, .8}}]}, {x, 0, 10}, MeshFunctions -> (#3 &), Mesh -> {Range[0, 10, .125]}, MeshStyle -> {Thick, Red}, PlotStyle -> None]} // Show $\endgroup$ – cvgmt Jan 21 at 15:06
4
$\begingroup$

This is a good use case for a Table:

{p2, p5, p8} = 
   Table[
     {10 - a, 0} + m({0, y[10 - a]} - {10 - a, 0}),
     {m, {0.2, 0.5, 0.8}},
     {a, 0, 10, 0.125}
   ]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.