Skip to content

Commit

Permalink
update 1dc479a feat: enable robots.txt (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Sep 1, 2024
1 parent cafcaf5 commit 9c5e1bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 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="a665f2248b281b3f76203a99ca3d20a03" width="100%" height="100%" viewBox="0 0 700 400"/><p id=c082f698f312223bd0cab74052a396a63 style=text-align:center>Caption</p></p><script type=module>
Such distribution doesn&rsquo;t look <em>natural</em>.</p><p><svg id="a4aabf35267803398021fc360692a2d2b" width="100%" height="100%" viewBox="0 0 700 400"/><p id=c692aa09fd8023c2163b80235f37426ab 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('a665f2248b281b3f76203a99ca3d20a03');
let svg = document.getElementById('a4aabf35267803398021fc360692a2d2b');

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

document.getElementById('c082f698f312223bd0cab74052a396a63').innerText = `${numPoints} points`;
document.getElementById('c692aa09fd8023c2163b80235f37426ab').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="a289c300ad4236f3182ba6572296f0b3a" width="100%" height="100%" viewBox="0 0 700 400"/><p id=c1225322bfaa96c39780a00f6364d832b 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="a9a36a600764903222c5281a2d8bff3b3" width="100%" height="100%" viewBox="0 0 700 400"/><p id=c6f8352b32964cb02f393182a6a07a02d 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('a289c300ad4236f3182ba6572296f0b3a');
let svg = document.getElementById('a9a36a600764903222c5281a2d8bff3b3');

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

document.getElementById('c1225322bfaa96c39780a00f6364d832b').innerText = `${points.length} points`;
document.getElementById('c6f8352b32964cb02f393182a6a07a02d').innerText = `${points.length} points`;

for (let p of points) {
let circle = document.createElementNS(svgns, 'circle');
Expand Down
6 changes: 3 additions & 3 deletions docs/posts/2024-07-29-random-points-in-circle/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<meta name=keywords content="procedural generation"><meta name=description content="angle = random(); distance = R * sqrt(random())"><meta name=author content><link rel=canonical href=https://andreynautilus.github.io/posts/2024-07-29-random-points-in-circle/><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 hreflang=en href=https://andreynautilus.github.io/posts/2024-07-29-random-points-in-circle/><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="Random points in circle with uniform distribution"><meta property="og:description" content="angle = random(); distance = R * sqrt(random())"><meta property="og:type" content="article"><meta property="og:url" content="https://andreynautilus.github.io/posts/2024-07-29-random-points-in-circle/"><meta property="article:section" content="posts"><meta property="article:published_time" content="2024-07-29T18:54:08+02:00"><meta property="article:modified_time" content="2024-07-29T18:54:08+02:00"><meta property="og:site_name" content="Andrey Nautilus blog"><meta name=twitter:card content="summary"><meta name=twitter:title content="Random points in circle with uniform distribution"><meta name=twitter:description content="angle = random(); distance = R * sqrt(random())"><script type=application/ld+json>{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"posts","item":"https://andreynautilus.github.io/posts/"},{"@type":"ListItem","position":2,"name":"Random points in circle with uniform distribution","item":"https://andreynautilus.github.io/posts/2024-07-29-random-points-in-circle/"}]}</script><script type=application/ld+json>{"@context":"https://schema.org","@type":"BlogPosting","headline":"Random points in circle with uniform distribution","name":"Random points in circle with uniform distribution","description":"angle = random(); distance = R * sqrt(random())","keywords":["procedural generation"],"articleBody":"We need to generate a random point in a circle with uniform distribution.\nA naive approach with polar coordinates by picking a random angle and a random distance doesn’t give uniform distribution - there are more points close to center and fewer points at the radius. This article has explanation and visualization.\nNNN points, left to right: naive approach, correct formula, Monte Carlo (XXX attempts) Correct formula for polar coordinates In polar coordinates:\nangle = random(0, 2 * PI) distance = R * sqrt(random(0, 1)) Where R is the radius of the circle. And transformation to Cortesian coordinates:\nx = distance * cos(angle) y = distance * sin(angle) This article and StackOverflow threads give a mathematically correct explanation.\nMonte Carlo (multiple attempts) Another approach is to generate uniformly distributed random points in the bounding box of the circle and pick the first point that is inside the circle.\nWith random() being a uniformly random number, the naive approach for a point in a square:\nx = random() y = random() give uniformly distributed points. And x * x + y * y \u003c= R * R provides an easy test for point being inside the circle.\nObvious drawback - undefined number of attempts, but with uniformly distributed points the average amount of attempt should not be greater than 2 (on average we need 4 / PI attempts).\n","wordCount":"227","inLanguage":"en","datePublished":"2024-07-29T18:54:08+02:00","dateModified":"2024-07-29T18:54:08+02:00","mainEntityOfPage":{"@type":"WebPage","@id":"https://andreynautilus.github.io/posts/2024-07-29-random-points-in-circle/"},"publisher":{"@type":"Organization","name":"Andrey Nautilus blog","logo":{"@type":"ImageObject","url":"https://andreynautilus.github.io/favicon.ico"}}}</script></head><body 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=post-single><header class=post-header><div class=breadcrumbs><a href=https://andreynautilus.github.io/>Home</a>&nbsp;»&nbsp;<a href=https://andreynautilus.github.io/posts/>posts</a></div><h1 class="post-title entry-hint-parent">Random points in circle with uniform distribution</h1><div class=post-meta><span title='2024-07-29 18:54:08 +0200 +0200'>July 29, 2024</span>&nbsp;·&nbsp;2 min</div></header><div class=post-content><p>We need to generate a random point in a circle with uniform distribution.</p><p>A naive approach with polar coordinates by picking a random angle and a random distance
doesn&rsquo;t give uniform distribution - there are more points close to center and fewer points at the radius.
<a href=https://www.anderswallin.net/2009/05/uniform-random-points-in-a-circle-using-polar-coordinates/>This article</a>
has explanation and visualization.</p><p><svg id="a2b3326078096ab3802a56f2213afc49d" width="100%" height="100%" viewBox="0 0 620 200"/><p id=c309a2bb05967f133860242aacf6d8223 style=text-align:center>NNN points, left to right: naive approach, correct formula, Monte Carlo (XXX attempts)</p></p><script type=module>
has explanation and visualization.</p><p><svg id="a14b233c5b2a886af697f90222303da60" width="100%" height="100%" viewBox="0 0 620 200"/><p id=c8b2963ac8322f614b03d32620a7af590 style=text-align:center>NNN points, left to right: naive approach, correct formula, Monte Carlo (XXX attempts)</p></p><script type=module>

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

let svg = document.getElementById('a2b3326078096ab3802a56f2213afc49d');
let svg = document.getElementById('a14b233c5b2a886af697f90222303da60');

const numPoints = 250;

Expand Down Expand Up @@ -40,7 +40,7 @@
svg.appendChild(circle);
}

let caption = document.getElementById('c309a2bb05967f133860242aacf6d8223');
let caption = document.getElementById('c8b2963ac8322f614b03d32620a7af590');
let text = caption.innerText;
text = text.replace("NNN", `${numPoints}`);
text = text.replace("XXX", `${attempts}`);
Expand Down

0 comments on commit 9c5e1bd

Please sign in to comment.