I have a parametric function defined by the x and y functions:

x = r*Cos[w_0*t - w_L*t] + 
  z*Cos[w_P*t - w_L*t]

y = r*Sin[w_0*t - w_L*t] + 
  z*Sin[w_P*t - w_L*t]

I can change the variables around to see interesting patterns formed by the function. What I want to do is have some sort of plot of this 2-D function where a grid is placed over the plot, and each square of the grid has the total amount of coverage of the function over the grid, meaning the total length of all the the lines passing through it. From the image, you can see that grid 3 has much more coverage than grid 4. That's what I want to quantify, but I really don't know how to attack the problem.

Basically, I want to set my parametric plot flat on a table and see the variation of density in different regions. Thus grids with lots of coverage will have a higher z-value. Perhaps there are other solutions to this than my idea, but I am certainly not sure.

enter image description here

  • $\begingroup$ You need to define "coverage" more rigorously. Naively, this could depend on the thickness of the lines you draw: make them thick enough and the whole square is "covered". If you can deal with pre-deciding a thickness, then perhaps rasterize the image, chop it up into rectangles, then measure how much red you have in each rectangle. Alternatively, you may want the area "enclosed" in the curve as a fraction of the area of the enclosing rectangle; that seems a much harder problem and you will need to develop this a bit more. $\endgroup$ – MarcoB May 1 at 15:41
  • $\begingroup$ Also, note that underscores have a special meaning and cannot be used as part of a variable name, so you may be trying to show subscripts there, but please look at this instead: How to copy Mathematica code so it looks good on this site. Generally speaking, avoid subscripts in calculations; they are really only for pretty-printing. $\endgroup$ – MarcoB May 1 at 15:42

Here is the image-processing idea I hinted at in comments. Let's define some values and get a pleasing plot:

w0 = 15 Pi; wL = 21 Pi; wP = 35 Pi; r = 1.5; z = 15;
x = r*Cos[w0*t - wL*t] + z*Cos[wP*t - wL*t];
y = r*Sin[w0*t - wL*t] + z*Sin[wP*t - wL*t];

plot = ParametricPlot[
         {x, y}, {t, 0, 1},
         PlotStyle -> Black,
         PlotRange -> {0, Automatic},
         PlotRangePadding -> {{0, Scaled[0.05]}, {0, Scaled[0.05]}},
         Axes -> False

plot, only curves, no axes

Then Rasterize the plot, Binarize the resulting image, then chop it up into 16 equal squares with ImagePartition:

(chopped = 
    plot // Rasterize[#, ImageResolution -> 150] & // Binarize // 
     ImagePartition[#, Scaled[1/4]] &) // Grid;

grid of squares from chopped image

Calculate the density of coverage for each square using the mean intensity of the corresponding image:

(densities = 
   1 - ImageMeasurements[#, "MeanIntensity"] & /@ chopped // 
    Round[#, 0.01] &) // Grid

(* Out: 
0.13    0.08    0.01    0.
0.      0.06    0.12    0.01
0.      0.      0.06    0.08
0.      0.      0.      0.13

I calculate (1-intensity) because that way high intensity/coverage corresponds to a low value, and viceversa; that helps with plotting later on.

Now combine the plot of the function with a visual representation of the density values, using ArrayPlot; note that plot range, data ranges etc need to be adjusted to match between the original plot and the density representation; I take the necessary values from the original plot:

    DataRange -> PlotRange[plot],
    ColorFunction -> (Blend[{White, Red}, #] &)
  PlotRange -> PlotRange[plot], 
  PlotRangePadding -> {{0, Scaled[0.05]}, {0, Scaled[0.05]}}

density plot overlaid on the function's line plot

| improve this answer | |
  • $\begingroup$ Amazing help there. Thank you. $\endgroup$ – Cameron_3298 May 2 at 17:14

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.