Skip to content

Commit

Permalink
update 59adafc fix: visualization random point in circle (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Aug 5, 2024
1 parent 19c5071 commit aaab979
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 38 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!doctype html><html lang=en dir=auto><head><meta name=generator content="Hugo 0.125.4"><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name=robots content="index, follow"><title>Andrey Nautilus blog</title>
<meta name=keywords content="Blog,Portfolio,PaperMod"><meta name=description content="Andrey Nautilus blog"><meta name=author content><link rel=canonical href=https://andreynautilus.github.io/><link crossorigin=anonymous href=/assets/css/stylesheet.b609c58d5c11bb90b1a54e04005d74ad1ddf22165eb79f5533967e57df9c3b50.css integrity="sha256-tgnFjVwRu5CxpU4EAF10rR3fIhZet59VM5Z+V9+cO1A=" rel="preload stylesheet" as=style><link rel=icon href=https://andreynautilus.github.io/favicon.ico><link rel=icon type=image/png sizes=16x16 href=https://andreynautilus.github.io/favicon-16x16.png><link rel=icon type=image/png sizes=32x32 href=https://andreynautilus.github.io/favicon-32x32.png><link rel=apple-touch-icon href=https://andreynautilus.github.io/apple-touch-icon.png><link rel=mask-icon href=https://andreynautilus.github.io/safari-pinned-tab.svg><meta name=theme-color content="#2e2e33"><meta name=msapplication-TileColor content="#2e2e33"><link rel=alternate type=application/json href=https://andreynautilus.github.io/index.json><link rel=alternate hreflang=en href=https://andreynautilus.github.io/><noscript><style>#theme-toggle,.top-link{display:none}</style><style>@media(prefers-color-scheme:dark){:root{--theme:rgb(29, 30, 32);--entry:rgb(46, 46, 51);--primary:rgb(218, 218, 219);--secondary:rgb(155, 156, 157);--tertiary:rgb(65, 66, 68);--content:rgb(196, 196, 197);--code-block-bg:rgb(46, 46, 51);--code-bg:rgb(55, 56, 62);--border:rgb(51, 51, 51)}.list{background:var(--theme)}.list:not(.dark)::-webkit-scrollbar-track{background:0 0}.list:not(.dark)::-webkit-scrollbar-thumb{border-color:var(--theme)}}</style></noscript><meta property="og:title" content="Andrey Nautilus blog"><meta property="og:description" content="Andrey Nautilus blog"><meta property="og:type" content="website"><meta property="og:url" content="https://andreynautilus.github.io/"><meta property="og:site_name" content="Andrey Nautilus blog"><meta name=twitter:card content="summary"><meta name=twitter:title content="Andrey Nautilus blog"><meta name=twitter:description content="Andrey Nautilus blog"><script type=application/ld+json>{"@context":"https://schema.org","@type":"Organization","name":"Andrey Nautilus blog","url":"https://andreynautilus.github.io/","description":"Andrey Nautilus blog","thumbnailUrl":"https://andreynautilus.github.io/favicon.ico","sameAs":["https://www.linkedin.com/in/andrey-potapov-1049b096/","https://github.com/AndreyNautilus"]}</script></head><body class=list id=top><script>localStorage.getItem("pref-theme")==="dark"?document.body.classList.add("dark"):localStorage.getItem("pref-theme")==="light"?document.body.classList.remove("dark"):window.matchMedia("(prefers-color-scheme: dark)").matches&&document.body.classList.add("dark")</script><header class=header><nav class=nav><div class=logo><a href=https://andreynautilus.github.io/ accesskey=h title="Andrey Nautilus blog (Alt + H)"><img src=https://andreynautilus.github.io/apple-touch-icon.png alt aria-label=logo height=35>Andrey Nautilus blog</a><div class=logo-switches><button id=theme-toggle accesskey=t title="(Alt + T)"><svg id="moon" xmlns="http://www.w3.org/2000/svg" width="24" height="18" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"/></svg><svg id="sun" xmlns="http://www.w3.org/2000/svg" width="24" height="18" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg></button></div></div><ul id=menu><li><a href=https://andreynautilus.github.io/links/ title=links><span>links</span></a></li><li><a href=https://andreynautilus.github.io/tags/ title=tags><span>tags</span></a></li><li><a href=https://andreynautilus.github.io/search/ title="search (Alt + /)" accesskey=/><span>search</span></a></li><li><a href=https://github.com/AndreyNautilus/AndreyNautilus.github.io title=src><span>src</span>&nbsp;<svg fill="none" shape-rendering="geometricPrecision" stroke="currentcolor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5" viewBox="0 0 24 24" height="12" width="12"><path d="M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"/><path d="M15 3h6v6"/><path d="M10 14 21 3"/></svg></a></li></ul></nav></header><main class=main><article class="first-entry home-info"><header class=entry-header><h1>Hi there 👋</h1></header><div class=entry-content>Welcome to my blog</div><footer class=entry-footer><div class=social-icons><a href=https://www.linkedin.com/in/andrey-potapov-1049b096/ target=_blank rel="noopener noreferrer me" title=linkedin><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 8a6 6 0 016 6v7h-4v-7a2 2 0 00-2-2 2 2 0 00-2 2v7h-4v-7a6 6 0 016-6z"/><rect x="2" y="9" width="4" height="12"/><circle cx="4" cy="4" r="2"/></svg>
</a><a href=https://github.com/AndreyNautilus target=_blank rel="noopener noreferrer me" title=github><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37.0 00-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44.0 0020 4.77 5.07 5.07.0 0019.91 1S18.73.65 16 2.48a13.38 13.38.0 00-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07.0 005 4.77 5.44 5.44.0 003.5 8.55c0 5.42 3.3 6.61 6.44 7A3.37 3.37.0 009 18.13V22"/></svg></a></div></footer></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>Random point in circle with uniform distribution</h2></header><div class=entry-content><p>angle = random(); distance = R * sqrt(random())</p></div><footer class=entry-footer><span title='2024-07-29 18:54:08 +0200 +0200'>July 29, 2024</span>&nbsp;·&nbsp;1 min</footer><a class=entry-link aria-label="post link to Random point in circle with uniform distribution" href=https://andreynautilus.github.io/posts/2024-07-29-random-point-in-circle/></a></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>Evenly distributed random points</h2></header><div class=entry-content><p>Bridson’s Algorithm to build Poisson disk distribution of points</p></div><footer class=entry-footer><span title='2024-07-21 20:16:16 +0200 +0200'>July 21, 2024</span>&nbsp;·&nbsp;3 min</footer><a class=entry-link aria-label="post link to Evenly distributed random points" href=https://andreynautilus.github.io/posts/2024-07-21-evenly-random-points-on-plane/></a></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>Linux process memory: RSS, VSZ, etc</h2></header><div class=entry-content><p>RSS, VSZ, PSS, USS explained</p></div><footer class=entry-footer><span title='2024-07-16 00:54:08 +0200 +0200'>July 16, 2024</span>&nbsp;·&nbsp;1 min</footer><a class=entry-link aria-label="post link to Linux process memory: RSS, VSZ, etc" href=https://andreynautilus.github.io/posts/2024-07-16-linux-process-memory/></a></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>Documenting code</h2></header><div class=entry-content><p>names = what, code = how, comments = why</p></div><footer class=entry-footer><span title='2024-05-26 19:05:29 +0200 +0200'>May 26, 2024</span>&nbsp;·&nbsp;1 min</footer><a class=entry-link aria-label="post link to Documenting code" href=https://andreynautilus.github.io/posts/2024-05-26-documenting-code/></a></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>git with multiple users</h2></header><div class=entry-content><p>Configure multiple git users on the same workstation</p></div><footer class=entry-footer><span title='2024-05-22 20:24:48 +0200 +0200'>May 22, 2024</span>&nbsp;·&nbsp;3 min</footer><a class=entry-link aria-label="post link to git with multiple users" href=https://andreynautilus.github.io/posts/2024-05-22-git-multiple-users/></a></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>git push --force vs --force-with-lease</h2></header><div class=entry-content><p>Prefer ‘git push –force-with-lease’ over ‘git push –force’</p></div><footer class=entry-footer><span title='2024-05-16 20:36:19 +0200 +0200'>May 16, 2024</span>&nbsp;·&nbsp;5 min</footer><a class=entry-link aria-label="post link to git push --force vs --force-with-lease" href=https://andreynautilus.github.io/posts/2024-05-16-git-force-vs-force-with-lease/></a></article></main><footer class=footer><span>&copy; 2024 <a href=https://andreynautilus.github.io/>Andrey Nautilus blog</a></span> ·
</a><a href=https://github.com/AndreyNautilus target=_blank rel="noopener noreferrer me" title=github><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentcolor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37.0 00-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44.0 0020 4.77 5.07 5.07.0 0019.91 1S18.73.65 16 2.48a13.38 13.38.0 00-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07.0 005 4.77 5.44 5.44.0 003.5 8.55c0 5.42 3.3 6.61 6.44 7A3.37 3.37.0 009 18.13V22"/></svg></a></div></footer></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>Random points in circle with uniform distribution</h2></header><div class=entry-content><p>angle = random(); distance = R * sqrt(random())</p></div><footer class=entry-footer><span title='2024-07-29 18:54:08 +0200 +0200'>July 29, 2024</span>&nbsp;·&nbsp;2 min</footer><a class=entry-link aria-label="post link to Random points in circle with uniform distribution" href=https://andreynautilus.github.io/posts/2024-07-29-random-points-in-circle/></a></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>Evenly distributed random points</h2></header><div class=entry-content><p>Bridson’s Algorithm to build Poisson disk distribution of points</p></div><footer class=entry-footer><span title='2024-07-21 20:16:16 +0200 +0200'>July 21, 2024</span>&nbsp;·&nbsp;3 min</footer><a class=entry-link aria-label="post link to Evenly distributed random points" href=https://andreynautilus.github.io/posts/2024-07-21-evenly-random-points-on-plane/></a></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>Linux process memory: RSS, VSZ, etc</h2></header><div class=entry-content><p>RSS, VSZ, PSS, USS explained</p></div><footer class=entry-footer><span title='2024-07-16 00:54:08 +0200 +0200'>July 16, 2024</span>&nbsp;·&nbsp;1 min</footer><a class=entry-link aria-label="post link to Linux process memory: RSS, VSZ, etc" href=https://andreynautilus.github.io/posts/2024-07-16-linux-process-memory/></a></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>Documenting code</h2></header><div class=entry-content><p>names = what, code = how, comments = why</p></div><footer class=entry-footer><span title='2024-05-26 19:05:29 +0200 +0200'>May 26, 2024</span>&nbsp;·&nbsp;1 min</footer><a class=entry-link aria-label="post link to Documenting code" href=https://andreynautilus.github.io/posts/2024-05-26-documenting-code/></a></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>git with multiple users</h2></header><div class=entry-content><p>Configure multiple git users on the same workstation</p></div><footer class=entry-footer><span title='2024-05-22 20:24:48 +0200 +0200'>May 22, 2024</span>&nbsp;·&nbsp;3 min</footer><a class=entry-link aria-label="post link to git with multiple users" href=https://andreynautilus.github.io/posts/2024-05-22-git-multiple-users/></a></article><article class=post-entry><header class=entry-header><h2 class=entry-hint-parent>git push --force vs --force-with-lease</h2></header><div class=entry-content><p>Prefer ‘git push –force-with-lease’ over ‘git push –force’</p></div><footer class=entry-footer><span title='2024-05-16 20:36:19 +0200 +0200'>May 16, 2024</span>&nbsp;·&nbsp;5 min</footer><a class=entry-link aria-label="post link to git push --force vs --force-with-lease" href=https://andreynautilus.github.io/posts/2024-05-16-git-force-vs-force-with-lease/></a></article></main><footer class=footer><span>&copy; 2024 <a href=https://andreynautilus.github.io/>Andrey Nautilus blog</a></span> ·
<span>Powered by
<a href=https://gohugo.io/ rel="noopener noreferrer" target=_blank>Hugo</a> &
<a href=https://github.com/adityatelange/hugo-PaperMod/ rel=noopener target=_blank>PaperMod</a></span></footer><a href=#top aria-label="go to top" title="Go to Top (Alt + G)" class=top-link id=top-link accesskey=g><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 6" fill="currentcolor"><path d="M12 6H0l6-6z"/></svg>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/posts/2024-07-21-evenly-random-points-on-plane/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
Possible use-cases:</p><ul><li>generate trees in a forest in a game world;</li><li>generate points for <a href=https://en.wikipedia.org/wiki/Voronoi_diagram>Voronoi diagram</a>
(with areas of similar size);</li></ul><p>The simplest approach - to use uniformly distributed points with <code>(random(), random())</code> - doesn&rsquo;t work,
because there will be areas with high density of points and areas with no points at all.
Such distribution doesn&rsquo;t look <em>natural</em>.</p><p><svg id="aa18026896f56c3b27034ab322d90fa23" width="100%" height="100%" viewBox="0 0 700 400"/><p id=c223b43ca1a896b0962ad533f0826f207 style=text-align:center>Caption</p></p><script type=module>
Such distribution doesn&rsquo;t look <em>natural</em>.</p><p><svg id="afdf622a3272902b6ca830693a310548b" width="100%" height="100%" viewBox="0 0 700 400"/><p id=c821332b8f536a903a60069d224bf2ca7 style=text-align:center>Caption</p></p><script type=module>

const svgns = 'http://www.w3.org/2000/svg';

const width = 700 ;
const height = 400 ;

let svg = document.getElementById('aa18026896f56c3b27034ab322d90fa23');
let svg = document.getElementById('afdf622a3272902b6ca830693a310548b');

const numPoints = 1700 ;
const points = generatePointsByUniformDistribution(width, height, numPoints);

document.getElementById('c223b43ca1a896b0962ad533f0826f207').innerText = `${numPoints} points`;
document.getElementById('c821332b8f536a903a60069d224bf2ca7').innerText = `${numPoints} points`;

for (let p of points) {
let circle = document.createElementNS(svgns, 'circle');
Expand All @@ -37,19 +37,19 @@
</script><p>Various types of grids with gaps can give even distribution, but the picture will not look <em>random</em>.
There will always be a pattern, sometimes more visible, sometimes less, but still visible. This
doesn&rsquo;t look <em>natural</em> either.</p><p>A solution to this problem is <a href=https://en.wikipedia.org/wiki/Supersampling#Poisson_disk>Poisson disk sampling (or Poisson disk distribution)</a>:
points are placed randomly, but not too close and not too far away from each other.</p><p><svg id="af8f06128aa32db963426ab3729c02530" width="100%" height="100%" viewBox="0 0 700 400"/><p id=c060d22fab242876ba3c383f6215903a9 style=text-align:center>Caption</p></p><script type=module>
points are placed randomly, but not too close and not too far away from each other.</p><p><svg id="aa57620031d33bc2ff9069a242a2b3886" width="100%" height="100%" viewBox="0 0 700 400"/><p id=c02da96506328f37a2b322a0169cbf348 style=text-align:center>Caption</p></p><script type=module>

const svgns = 'http://www.w3.org/2000/svg';

const width = 700 ;
const height = 400 ;

let svg = document.getElementById('af8f06128aa32db963426ab3729c02530');
let svg = document.getElementById('aa57620031d33bc2ff9069a242a2b3886');

const radius = 10 ;
const points = generatePointsByPoissonDiskDistribution(width, height, radius);

document.getElementById('c060d22fab242876ba3c383f6215903a9').innerText = `${points.length} points`;
document.getElementById('c02da96506328f37a2b322a0169cbf348').innerText = `${points.length} points`;

for (let p of points) {
let circle = document.createElementNS(svgns, 'circle');
Expand Down Expand Up @@ -182,7 +182,7 @@
and <code>2r</code> form the selected point <code>p-i</code>; test every generated point if it&rsquo;s far enough (<code>dist >=r</code>)
from already existing points (use the grid to test only nearby cells);<ul><li>if a generated point is far enough from all existing points, add it to the list of <em>generated points</em>,
update the <em>grid cell</em> with its index and add this new point to <em>active points</em>;</li><li>if all <code>k</code> points are too close to already existing points, then remove <code>p-i</code> from <em>active points</em>;</li></ul></li><li>repeat until list of <em>active points</em> is empty;</li></ol><p>Side notes:</p><ul><li>complexity is <code>O(N)</code>;</li><li>easy to implement;</li><li>the cluster of points grows <em>naturally</em> from the starting point to all directions;</li><li>easily extensible to 3D (and more dimensional) space;</li><li>the number of points is not known until the generation process is complete (it&rsquo;s &ldquo;generate <em>some</em>
points with specific condition&rdquo; rather than &ldquo;generate N points&rdquo;);</li></ul><h2 id=links>Links<a hidden class=anchor aria-hidden=true href=#links>#</a></h2><ul><li><a href=https://www.jasondavies.com/poisson-disc/>https://www.jasondavies.com/poisson-disc/</a></li></ul></div><footer class=post-footer><ul class=post-tags><li><a href=https://andreynautilus.github.io/tags/procedural-generation/>procedural generation</a></li></ul><nav class=paginav><a class=prev href=https://andreynautilus.github.io/posts/2024-07-29-random-point-in-circle/><span class=title>« Prev</span><br><span>Random point in circle with uniform distribution</span>
points with specific condition&rdquo; rather than &ldquo;generate N points&rdquo;);</li></ul><h2 id=links>Links<a hidden class=anchor aria-hidden=true href=#links>#</a></h2><ul><li><a href=https://www.jasondavies.com/poisson-disc/>https://www.jasondavies.com/poisson-disc/</a></li></ul></div><footer class=post-footer><ul class=post-tags><li><a href=https://andreynautilus.github.io/tags/procedural-generation/>procedural generation</a></li></ul><nav class=paginav><a class=prev href=https://andreynautilus.github.io/posts/2024-07-29-random-points-in-circle/><span class=title>« Prev</span><br><span>Random points in circle with uniform distribution</span>
</a><a class=next href=https://andreynautilus.github.io/posts/2024-07-16-linux-process-memory/><span class=title>Next »</span><br><span>Linux process memory: RSS, VSZ, etc</span></a></nav></footer></article></main><footer class=footer><span>&copy; 2024 <a href=https://andreynautilus.github.io/>Andrey Nautilus blog</a></span> ·
<span>Powered by
<a href=https://gohugo.io/ rel="noopener noreferrer" target=_blank>Hugo</a> &
Expand Down
Loading

0 comments on commit aaab979

Please sign in to comment.