4
$\begingroup$

I am trying to create a table of points, where the size of the step would change linearly from a certain value to another. Bellow is a simple code to demonstrate a table of points with a constant step in X and Y direction.

MasterMesh=Flatten[Table[{XX , YY, 0}, {XX, -1/2, 1/2, 0.2}, {YY, -1/2, 1/2, 0.2}], 1];
ListPointPlot3D[MasterMesh]

enter image description here

My goal would ultimately be, to create a raster of point that is something like shown in the figure bellow (drawn clumsily), where the distances between the new points (marked red bellow) are supposed to change linearly in a way that L1:L2:L3:L4:L5=1:2:3:4:5. enter image description here

Any help will be much appreciated!

$\endgroup$
4
$\begingroup$
g1 = Prepend[Accumulate@Range[5], 0]
(* {0, 1, 3, 6, 10, 15} *)

g2 = Prepend[Accumulate@Reverse@Range[5], 0]
(* {0, 5, 9, 12, 14, 15} *)

Join @@ MapIndexed[{First[#2], #1, 0} &,
   Subdivide[g1, g2, 5],
   {2}
   ] // ListPointPlot3D

enter image description here

$\endgroup$
  • $\begingroup$ Thank you for this answer. In a way, this code does what I asked in the question. The only drawback is that I need the distance between the first and last point in X or Y direction to be controlled independently and not related to the number of subdivisions. As is stands now, if I want 5 subdivisions in Y direction, I get the min and max Y coordinate of 1 and 6 respectively. Changing the number of subdivisions to 10, makes them 1 and 11. $\endgroup$ – marko Nov 22 '18 at 10:19
  • $\begingroup$ @marko I don't understand your comment. In my code, the mesh size is set independently in the two directions. I also do not understand which direction you are referring to as $x$ and $y$. $\endgroup$ – Szabolcs Nov 22 '18 at 10:21
  • $\begingroup$ Sorry for the unclear comment. As it stands now, the number of subdivisions (set to 5) defined in Subdivide[g1, g2, 5] defines also the length of the mesh in this direction (the direction I called "Y"). Setting the number of divisions to 10, will change the length of the mesh to 10. Is there a way to keep this constant? Similarly, I wish to keep the length of the mesh in the other direction constant (now it is 15), regardless of the number of divisions. Let's say that I wish the mesh to be of length 10 in both directions. Hopefully this is more clear. $\endgroup$ – marko Nov 22 '18 at 10:29
  • $\begingroup$ @marko You can scale the mesh by inserting the required scaling factor in front of the first or second element of {First[#2], #1, 0} in MapIndexed. A bit inconvenient, as you'd need to sync the factor with the value in Range and Subdivide, but it will work :-) $\endgroup$ – Szabolcs Nov 22 '18 at 10:39
  • $\begingroup$ Thank you. I managed to get it working, using the code bellow, where I define number of elements in both directions and the length (for a hyperbolic paraboloid) NumElements1 = 16; NumElements2 = 10; len = 2; g1 = Prepend[Accumulate@Range[NumElements2], 0]; g2 = Prepend[Accumulate@Reverse@Range[NumElements2], 0]; Flatten[MapIndexed[{len/ Last[g1]*#1, (len/(NumElements1 + 1))*(First[#2] - 1), (len/Last[g1]*#1 - len/2)^2 - ((len/(NumElements1 + 1))*(First[#2] - 1) - len/2)^2} &, Subdivide[g1, g2, NumElements1], {2}], 1] // ListPointPlot3D $\endgroup$ – marko Nov 22 '18 at 12:35
2
$\begingroup$
MasterMesh =
  Flatten[Table[{1.7^x, 1.7^y, 0},
    {x, 1, 2, .1},
    {y, 1, 2, .1}], 1];
ListPointPlot3D[MasterMesh]
$\endgroup$
  • $\begingroup$ Your code indeed produces something similar to what I would need, but the step length is not increasing in a way that I wish. For the set of data that you provided, it goes: L1=0.19, L2=0.21, L3=0.24. Also the max distance in X or Y direction, location of the first point and the step change seem to be all dependable on each other. $\endgroup$ – marko Nov 22 '18 at 9:25
2
$\begingroup$

You can change n and range

n = 5
range = .5
d = 2 range/n
x = FoldList[# + 1/(n*(n + 1)/2)*#2*2 range &, -range, Range@n];
h = Table[{x[[i]], j, 0}, {i, n + 1}, {j, -range, range, d}];
g = Table[Diagonal@Table[{i, k, 0}, {i, x[[j]], -x[[-j]], 
  Abs[x[[j]] + x[[-j]]]/(n + 1)}, {k, -range, range, d}], {j, 2, n}];
ListPointPlot3D[Join[{h[[1]]}, g, {h[[n + 1]]}],PlotStyle -> PointSize[Large]]    

enter image description here

n=12 and range=2     

enter image description here

$\endgroup$
1
$\begingroup$

Maybe someone will find this useful, so here is my code to achieve mesh distortion in both directions. It is achieved using the answer by Szabolcs and the Line-line intersection equation, taken from Wikipedia.

NumElements1 = 10;
NumElements2 = 4;
ratio = 2;

x[n_, ratio_] := 
 Normalize[
  Accumulate[
   Join[{0}, Table[1 + (i - 1)/(n - 1) (ratio - 1), {i, 1, n}]]], Max]
reversex[n_, ratio_] := 
 Normalize[
  Accumulate[
   Join[{0}, 
    Reverse[Table[1 + (i - 1)/(n - 1) (ratio - 1), {i, 1, n}]]]], Max]

g1 = x[NumElements1, ratio];
g2 = reversex[NumElements1, ratio];

g3 = x[NumElements2, ratio];
g4 = reversex[NumElements2, ratio];

Flatten[Table[
   MapThread[{(-#1 + (#1 - #2)*
        g3[[i]])/((#1 - #2)*(g3[[i]] - g4[[i]]) - 
       1), (#1*(g3[[i]] - g4[[i]]) - 
       g3[[i]])/((#1 - #2)*(g3[[i]] - g4[[i]]) - 1), 0} &, {g1, 
     g2}], {i, 1, NumElements2 + 1}], 1] // ListPointPlot3D

By changing ratio and NumElements1 and NumElements2, you can get the desired output. For the data above I get this: enter image description here

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