Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SeedRandom[1]
- region = ConvexHullMesh[RandomReal[1, {100, 2}]];
- UniformPts =
- Union[RandomPoint[region, 50000],
- SameTest -> (EuclideanDistance[#1, #2] < .1 &)];
- Show[region, Graphics[Point[UniformPts]]]
- region = ConvexHullMesh[RandomReal[1, {100, 2}]];
- << NDSolve`FEM`
- elementMesh = ToElementMesh[region, MeshQualityGoal -> 0];
- coordinates = elementMesh[[1]];
- triangles = elementMesh[[2, 1, 1]];
- centers =
- Table[
- Sum[{coordinates[[triangles[[i, j]], 1]],coordinates[[triangles[[i, j]], 2]]}, {j, 1, 3}]/3
- , {i, 1, Length[triangles]}];
- Show[region, Graphics[Point[centers]]]
- region = ConvexHullMesh[RandomReal[1, {100, 2}]];
- spacing = 1/40;
- test[x_] := RegionMember[region, x];
- points = DeleteCases[
- Flatten[Table[ If[test[{i, j}], {i, j}, -1] , {i, 0, 1, spacing}, {j, 0, 1, spacing}], 1]
- , -1];//AbsoluteTiming
- Show[region, Graphics[Point[points]]]
- With[{reg = RegularPolygon[5]},
- Nest[RegionNearest[reg][
- RegionCentroid@RegionIntersection[reg, #] & /@
- MeshPrimitives[VoronoiMesh@#, 2]] &, RandomPoint[reg, 20], 20] //
- Graphics[{LightBlue, reg, Black, Point@#}] &]
- With[{reg = RegularPolygon[5]},
- With[{points = 500, samples = 40000, iterations = 20},
- Nest[With[{randoms = Join[#, RandomPoint[reg, samples]]},
- RegionNearest[reg][
- Mean@randoms[[#]] & /@
- Values@PositionIndex@Nearest[#, randoms]]] &,
- RandomPoint[reg, points], iterations]] //
- Graphics[{LightBlue, reg, Black, Point@#}] &]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement