Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. SeedRandom[1]
  2. region = ConvexHullMesh[RandomReal[1, {100, 2}]];
  3. UniformPts =
  4. Union[RandomPoint[region, 50000],
  5. SameTest -> (EuclideanDistance[#1, #2] < .1 &)];
  6. Show[region, Graphics[Point[UniformPts]]]
  7.  
  8. region = ConvexHullMesh[RandomReal[1, {100, 2}]];
  9. << NDSolve`FEM`
  10. elementMesh = ToElementMesh[region, MeshQualityGoal -> 0];
  11. coordinates = elementMesh[[1]];
  12. triangles = elementMesh[[2, 1, 1]];
  13. centers =
  14. Table[
  15. Sum[{coordinates[[triangles[[i, j]], 1]],coordinates[[triangles[[i, j]], 2]]}, {j, 1, 3}]/3
  16. , {i, 1, Length[triangles]}];
  17. Show[region, Graphics[Point[centers]]]
  18.  
  19. region = ConvexHullMesh[RandomReal[1, {100, 2}]];
  20. spacing = 1/40;
  21. test[x_] := RegionMember[region, x];
  22. points = DeleteCases[
  23. Flatten[Table[ If[test[{i, j}], {i, j}, -1] , {i, 0, 1, spacing}, {j, 0, 1, spacing}], 1]
  24. , -1];//AbsoluteTiming
  25. Show[region, Graphics[Point[points]]]
  26.  
  27. With[{reg = RegularPolygon[5]},
  28. Nest[RegionNearest[reg][
  29. RegionCentroid@RegionIntersection[reg, #] & /@
  30. MeshPrimitives[VoronoiMesh@#, 2]] &, RandomPoint[reg, 20], 20] //
  31. Graphics[{LightBlue, reg, Black, Point@#}] &]
  32.  
  33. With[{reg = RegularPolygon[5]},
  34. With[{points = 500, samples = 40000, iterations = 20},
  35. Nest[With[{randoms = Join[#, RandomPoint[reg, samples]]},
  36. RegionNearest[reg][
  37. Mean@randoms[[#]] & /@
  38. Values@PositionIndex@Nearest[#, randoms]]] &,
  39. RandomPoint[reg, points], iterations]] //
  40. Graphics[{LightBlue, reg, Black, Point@#}] &]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement