0
$\begingroup$

I'd like to write a function plot[reg_,f_] that takes as input any product of intervals (list of pairs of reals) reg$\subseteq\!\mathbb{R}^d$ and a map/parametrization (pure function) $f:D\longrightarrow\mathbb{R}^n$, where $n\!\in\!\{2,3\}$ and $1\!\leq\!d\!\leq\!n$, and plot its trajectory. Examples of use:

plot[{{0,2Pi}},               {Cos[#],Sin[#]}&]                                  (*circle*)
plot[{{0,2Pi},{0,1}},         #2{Cos[#1],Sin[#1]}&]                              (*filled circle*)
plot[{{0,2},{0,1}},           {#1,#2}&]                                          (*filled rectangle*)
plot[{{0,2Pi}},               {Sin[#]+2Sin[2#],Cos[#]-2Cos[2#],-Sin[3#]}&];      (*trefoil knot*)
plot[{{0,2Pi},{0,2Pi}},       {(3+Cos[#1])Cos[#2],(3+Cos[#1])Sin[#2],Sin[#1]}&]; (*torus*)
plot[{{0,2Pi},{-Pi,Pi},{0,1}},#3{Cos[#1]Cos[#2],Cos[#1]Sin[#2],Sin[#1]}&];       (*filled sphere*)

While writing this question, I wanted to give my attempt at this problem. In the end, I solved it, so I am sharing it below, in hopes it helps someone else too.

$\endgroup$
1
$\begingroup$
plot[reg_,f_] := Module[{tr=Transpose,d=Length@reg,n=Length@f[[1]],v,o}, 
   v = Table[Unique[],{i,d}]; o={f@@v,Sequence@@tr@Prepend[tr@reg,v],PlotRange->All};
   If[n==2,Return[ParametricPlot@@o]];
   If[n==3,Return[ParametricPlot3D@@o]]; ];
$\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.