2

What I am looking for is something like the output of this code:

DiscretizeRegion[Line[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}],
                 MaxCellMeasure -> {"Length" -> 0.1}]

but I just want to have a list of the points on this line.

Thanks

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
ab123214
  • 21
  • 2

2 Answers2

8

This is easily done with Subdivide[] and some deft use of dot products:

lineSubdivide[{p1_, p2_}, n_Integer?Positive] :=
    With[{t = Subdivide[n]}, Transpose[{1 - t, t}] . {p1, p2}]

{Graphics[Point[lineSubdivide[{{0, 0}, {1, 1}}, 10]], Axes -> True], Graphics3D[Point[lineSubdivide[{{0, 0, 0}, {1, 1, 1}}, 10]]]}

subdivided lines in 2D and 3D

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
7
  • Subdivide support multiple coordinate.
Subdivide[{0, 0, 0}, {1, 1, 1}, 10]

enter image description here

  • MeshPrimitives can get the coordinates. ( Here we do not use MeshCoordinates since it not always in order.)
reg = DiscretizeRegion[Line[{p1, p2}], 
   MaxCellMeasure -> {"Length" -> 1/5}];
MeshPrimitives[reg, 1][[;; , 1]]

enter image description here

cvgmt
  • 72,231
  • 4
  • 75
  • 133