1
$\begingroup$

I have these two codes:

(1)

m = 100;
Do[ s[i] = N[2 Pi (i - 1)/m];
    r[i] = N[Exp[Cos[s[i]]] (Cos[2 s[i]])^2 
           + Exp[Sin[s[i]]] (Sin[2 s[i]])^2];
   ET[i] = N[r[i] Exp[I s[i]]],{i, 1, m + 1}]

RShape = ListPlot[Table[{Re[ET[i]], Im[ET[i]]}, {i, m + 1}], 
PlotStyle -> Black, Joined -> True, AspectRatio -> Automatic, 
PlotRange -> {{-2, 3}, {-1.5, 2}}, Axes -> False, 
Frame -> {{True, False}, {True, False}}, 
FrameTicks -> {{{-2, -1, 0, 1, 2}, None}, {{-2, -1, 0, 1, 2, 3}, 
   None}},
FrameLabel -> {Re[eta], Im[eta]}, RotateLabel -> False, 
FrameStyle -> Directive[FontSize -> 25]] /. Line -> Arrow;

Show[RShape]

and (2)

ListPlot[Table[{x, y}, {x, -2, 3, 0.05}, {y, -2, 2, 0.05}], PlotStyle -> 
Black]

I'm trying to plot series of points from code (2) inside region plotted in code (1); with a condition that only points inside the region will be plotted (no points on the outside and on the boundary of the region). By having this condition, I understand that I can use RegionFunction command

RegionFunction -> Function[{x, y, z},
Sqrt[x^2 + y^2] < Exp[Cos[ArcTan[x, y]]] (Cos[2 ArcTan[x, y]])^2 +
Exp[Sin[ArcTan[x, y]]] (Sin[2 ArcTan[x, y]])^2] 

Please help me find the suitable plot command to combine all this ideas. Thank you.

$\endgroup$
1
$\begingroup$
Clear[s, r, ET]

m = 100;

s[i_] = 2 Pi (i - 1)/m;

r[i_] = Exp[Cos[s[i]]] (Cos[2 s[i]])^2 + 
   Exp[Sin[s[i]]] (Sin[2 s[i]])^2;

ET[i_] = r[i] Exp[I s[i]];

shapeData = Table[ReIm[ET[i]], {i, m + 1}] // N;

pts = Select[
   Table[{x, y}, {x, -2, 3, 0.05}, {y, -2, 2, 0.05}] //
    Flatten[#, 1] &,
   RegionMember[Polygon[shapeData], #] &];

Show[
 ListLinePlot[shapeData,
   PlotStyle -> Black,
   PlotRange -> {{-2, 3}, {-1.5, 2}},
   Axes -> False,
   Frame -> {{True, False}, {True, False}},
   FrameTicks -> {
     {Range[-2, 2], None},
     {Range[-2, 3], None}},
   FrameLabel -> ReIm[eta],
   RotateLabel -> False,
   FrameStyle -> Directive[FontSize -> 25]] /.
  Line -> Arrow,
 ListPlot[pts, PlotStyle -> Black]]

enter image description here

Or

ListPlot[{shapeData, pts},
  Joined -> {True, False},
  PlotStyle -> Black,
  PlotRange -> {{-2, 3}, {-1.5, 2}},
  Axes -> False,
  Frame -> {{True, False}, {True, False}},
  FrameTicks -> {
    {Range[-2, 2], None},
    {Range[-2, 3], None}},
  FrameLabel -> ReIm[eta],
  RotateLabel -> False,
  FrameStyle -> Directive[FontSize -> 25]] /.
 Line -> Arrow
$\endgroup$
  • $\begingroup$ How am I going to call this pts in the forms of pts[i,j] since I need to do numerical calculation for points inside the region? $\endgroup$ – minsat_hsn Aug 27 '17 at 4:01
  • $\begingroup$ @minsat_hsn - Each element of pts is in the form {x, y}. To apply f[x, y] to pts use f@@@pts $\endgroup$ – Bob Hanlon Aug 27 '17 at 4:35
1
$\begingroup$

using textures:

Show[{ 
  Graphics[{Texture[
     Graphics[{PointSize[.01], 
       Point@Flatten[Table[{x, y}, {x, -1, 1, 0.1}, {y, -1, 1, 0.1}], 
         1]}, ImagePadding -> False, ImageMargins -> False, 
      PlotRange -> {{-1, 1}, {-1, 1}}]], 
    Polygon[p, VertexTextureCoordinates -> p]}],RShape}]

enter image description here

this is a bit tricky if you really need to control the point spacing, but is fast if you just want a graphic with a dot pattern.

$\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.