[Oberon] Oberon-7 - Circle Segments
John R. Strohm
strohm at airmail.net
Wed Feb 20 01:49:08 CET 2019
You can do an iterative approximation using multiply and add/subtract.
I don't guarantee the following. You'll need to recheck the trig and the derivation.
Recall from basic trigonometry:
cos u+du = cos u cos du - sin u sin du
sin u+du = sin u cos du + cos u sin du
Set du to your step size in radians, and precalculate cos du and sin du. Call them c and s, respectively.
Set u to 0, precalculate initial x = cos 0 = 1.0 and y = sin 0 = 0.0.
Then the iteration becomes something along the lines of:
x_new := x * c - y * s;
y_new := y * c + x * s;
x := x_new;
y := y_new;
The catch is that you will need a wide, precise multiply and add.
You may have to synthesize this from single-precision integer multiplication if you don't have a stable double-precision floating-point system.
Consider using rounding bits in the two iteration addition steps, to control rounding error.
--- schierlm at gmx.de wrote:
From: Michael Schierl <schierlm at gmx.de>
To: ETH Oberon and related systems <oberon at lists.inf.ethz.ch>
Subject: Re: [Oberon] Oberon-7 - Circle Segments
Date: Tue, 19 Feb 2019 22:52:14 +0100
Hello Tomas,
Am 19.02.2019 um 18:23 schrieb Tomas Kral:
> I probably cannot do without trigonometry, right?
sine and cosine of 30°/60°/90° are all nice values (0, 0.5, sqrt(0.75),
1), so you can hardcode the values. For the square root you can use an
approximation if you want to avoid calculating it.
Regards,
Michael
--
Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
https://lists.inf.ethz.ch/mailman/listinfo/oberon
More information about the Oberon
mailing list