Skip to content

Instantly share code, notes, and snippets.

@akhiljalagam
Created June 30, 2020 03:32
Show Gist options
  • Save akhiljalagam/cc2881ab6d841f0cfb7f3fd0b837fc9f to your computer and use it in GitHub Desktop.
Save akhiljalagam/cc2881ab6d841f0cfb7f3fd0b837fc9f to your computer and use it in GitHub Desktop.
function calc1(form) {
a = form.a.value;
b = Math.round(Math.pow(Math.pow(a, 2)/1.31640624208984, .5)/2.97869411418791);
c = Math.round(Math.pow(Math.pow(a, 2)/1.31640624208984, .5)/4.46804291661112);
d = Math.round(Math.pow(Math.pow(a, 2)/1.31640624208984, .5)/6.70206437491669);
e = Math.round(Math.pow(Math.pow(a, 2)/1.31640624208984, .5)/13.9626341144098);
f = Math.round(Math.pow(Math.pow(a, 2)/1.31640624208984, .5)/27.9252682288196);
form.total1.value = b;
form.total2.value = c;
form.total3.value = d;
form.total4.value = e;
form.total5.value = f;
}
<form>Enter screen size:<input name="a" size="3" type="number" autocomplete="off"> inches diagonal <input type="button" value="Calculate" onclick="calc1(this.form)"><p></p>
<ul>
<li>For <strong>480p</strong> (720×480) resolution, you must sit:<br>
<input maxlength="40" name="total1" size="3" type="text"> feet <em>or closer</em> to see all available detail</li>
<li>For <strong>720p</strong> (1280×720) resolution, you must sit:<br>
<input maxlength="40" name="total2" size="3" type="text"> feet <em>or closer</em> to see all available detail</li>
<li>For <strong>1080p</strong> (1920×1080) resolution, you must sit:<br>
<input maxlength="40" name="total3" size="3" type="text"> feet <em>or closer</em> to see all available detail</li>
<li>For <strong>4k</strong> (3840×2160) resolution, you must sit:<br>
<input maxlength="40" name="total4" size="3" type="text"> feet <em>or closer</em> to see all available detail</li>
<li>For <strong>8k</strong> (7680×4320) resolution, you must sit:<br>
<input maxlength="40" name="total5" size="3" type="text"> feet <em>or closer</em> to see all available detail</li>
</ul>
</form>
@shane-in-the-uk
Copy link

shane-in-the-uk commented Mar 1, 2021

Hi,

Sorry to bug you but I'm messing around with a distance calculator (more to understand how it works - hobbyist) and I'm struggling to figure out where these much needed numbers are generated from

1.31640624208984, 5, 4.46804291661112, 6.70206437491669, 13.9626341144098 and 27.9252682288196

Any points towards the right direction would be greatly appreciated

Cheers, Shane

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment