2
$\begingroup$

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

$\endgroup$
3

2 Answers 2

8
$\begingroup$

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

$\endgroup$
0
7
$\begingroup$
  • 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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.