Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #38055
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2020-01-13 10:01 -0800 |
| References | <8fe5af4b-242f-460f-b546-4a2ed830d1eb@googlegroups.com> <qv6nnc$h44$1@gioia.aioe.org> <4ca72c7b-2cfd-4310-82d3-0fa8a917d889@googlegroups.com> <9c881808-2ee9-42c0-b964-b4f33f586b8a@googlegroups.com> |
| Message-ID | <23eb3622-4837-4800-81d9-e092ef376b04@googlegroups.com> (permalink) |
| Subject | Re: Refreshing grade school math. |
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
Den söndag 12 januari 2020 kl. 07:13:13 UTC+1 skrev Julio Di Egidio:
> On Saturday, 11 January 2020 14:09:55 UTC+1, Jonas Thörnvall wrote:
>
> > This is what i try to do but without use of cosinus and sinus.
>
> LOL. To begin with, my congratulations for some reasonably readable
> code. That said, and nitpicking aside (e.g. on the still too prominent
> use of globals, as well as probably some plain forgetting of the var
> keyword on some locals), I'd raise a couple of main points:
>
> Firstly, I think it's messed up with nodes vs arr: on the first line
> you are using nodes as a count, later you count m up to arr.length,
> where arr I must guess is a global: this is too messy, either one or
> the other. Indeed, to make it clean, I would suggest that all you
> actually need is a function that gets a count in input, the count of
> distinct points, and returns a brand new array with the needed
> coordinates, whose length of course will be that count. (And,
> printnode looks like an indirect index: but your function shouldn't
> be bothered with "external" considerations, i.e. just build and
> return an array and rather do that on the caller's side if you
> really need. At least, from what I can gather...) (Plus, those
> radius and offsets better be defined in some outer scope, even be
> globals if nothing else, anyway not hard-coded into the function.)
>
> Secondly, that logic of calculating the single step, then adding it
> repeatedly, plain accumulates floating-point errors, so it is not the
> way to write such a loop. What you rather do is:
>
> var sect = 2 * Math.PI / count;
> for (var m = 0; m < count; ++m) {
> var theta = sect * m;
> ...
>
> You still get a minimum of floating-point error there, but it will
> not accumulate.
>
> Also, you do not usually need to round off coordinates, certainly
> not for drawing. If you thought pixel coordinates on a canvas are
> integers, note that they aren't...
>
> > function circleNodes(nodes) {
> > var step = 2 * Math.PI / (nodes);
> > var h = 670;
> > var k = 370;
> > var r = 320;
> > theta = 0;
> > for (var m = 0; m < arr.length; m++) {
> > nodeout = printnode[m];
> > var MX = h + r * Math.cos(theta);
> > var MY = k - r * Math.sin(theta);
> > arr[nodeout].rposX = Math.round(MX);
> > arr[nodeout].rposY = Math.round(MY);
> > theta += step
> > }
> > }
>
> I could have rewritten it with my suggestions incorporated, it's few
> lines of code, but I wouldn't want to spoil the exercise...
>
> HTH,
>
> Julio
By the way what do you mean by that the X, Y cordinates not limited to the integer cordinate space. Can computers move pixels slightly by diffuse aspects of them????? I mean the number of pixels is fixed so "WHY" isn't the pixels integer cordinates?
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-08 23:54 -0800
Re: Refreshing grade school math. "R.Wieser" <address@not.available> - 2020-01-09 09:19 +0100
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-09 00:34 -0800
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-09 00:43 -0800
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-09 00:44 -0800
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-11 05:09 -0800
Re: Refreshing grade school math. Julio Di Egidio <julio@diegidio.name> - 2020-01-11 22:13 -0800
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-13 09:58 -0800
Re: Refreshing grade school math. Julio Di Egidio <julio@diegidio.name> - 2020-01-13 10:16 -0800
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-13 11:16 -0800
Re: Refreshing grade school math. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-01-13 12:22 -0800
Re: Refreshing grade school math. Julio Di Egidio <julio@diegidio.name> - 2020-01-13 12:53 -0800
Re: Refreshing grade school math. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-01-13 15:31 -0800
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-13 16:03 -0800
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-13 13:00 -0800
Re: Refreshing grade school math. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-01-13 15:35 -0800
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-13 15:43 -0800
Re: Refreshing grade school math. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-01-14 01:01 +0100
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-13 16:07 -0800
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-13 10:01 -0800
Re: Refreshing grade school math. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-01-13 10:04 -0800
csiph-web