1

Topic: It was tangled in three corners, mathematicians, help

Hello! There is an arc, is set by radius, an initial corner, finite, and a bypass direction - clockwise or against. It is necessary to receive dFi - a difference between a finite and initial corner. It can be both positive, and negative - a sign will specify a bypass direction, i.e. as a result an arc should be set in radius, an initial corner and a corner increment. Tried to subtract from a finite corner initial - does not work. Two corners, 90 and 30, a direction on the hour. 30 - 90 =-60,  like. I try on the contrary - should the circle without sector turns out, and it turns out as a result of 90 - 30 = 60, i.e. the same 60, is simple with other sign, and should be 300. Tried  corners in 0 - 360, or in-180 - +180, tried to search for addition to 360 - all the same or in half of cases not that quits, or in a quarter. , I can not think. The mathematics after HIGH SCHOOL somehow was not necessary generally, anything any more I do not remember Kick in the necessary direction

2

Re: It was tangled in three corners, mathematicians, help

Hello, Marty, you wrote: M> Hello! M> there is an arc, is set by radius, an initial corner, finite, and a bypass direction - clockwise or against. M> It is necessary to receive dFi - a difference between a finite and initial corner. It can be both positive, and negative - a sign will specify a bypass direction, i.e. as a result an arc should be set in radius, an initial corner and a corner increment. M> tried to subtract from a finite corner initial - does not work. Two corners, 90 and 30, a direction on the hour. 30 - 90 =-60,  like. I try on the contrary - should the circle without sector turns out, and it turns out as a result of 90 - 30 = 60, i.e. the same 60, is simple with other sign, and should be 300. Tried  corners in 0 - 360, or in-180 - +180, tried to search for addition to 360 - all the same or in half of cases not that quits, or in a quarter. S - initial corner E - a finite corner If a direction - against hour, if (E <S) {E + = 360} And further delta = E - S If on hour, (is lazy to deduce the formula): we do swap (S, E), and we consider under the formula for CCW Check further.

3

Re: It was tangled in three corners, mathematicians, help

Hello, V. Zudin, you wrote: SVZ> Check. Does not work. Implementation: double calcAngleDelta (double s, double e, bool ccw) {if (ccw) {if (e <s) e + = 360.0; return e - s;} return calcAngleDelta (e, s, true);} Not , like? Does not work generally Even there where at me it was half correct, now all not so.

4

Re: It was tangled in three corners, mathematicians, help

Hello, Marty, you wrote: M> does not work. M> implementation: M> double calcAngleDelta (double s, double e, bool ccw) M> {M> if (ccw) M> {M> if (e <s) M> e + = 360.0; M> return e - s; M>} M> return calcAngleDelta (e, s, true); M>} M> Not , like? I would do without a recursion, but as a whole the code looks truly. Give on steps. 1 s = 0, e = 90, ccw = true delta = 90 - 0 = 90 test 2 s = 90, e = 0, ccw = true e = 0 + 360 = 360 delta = 360 - 90 = 270 test 3 s = 135, e = 45, ccw = true e = 45 + 360 = 405 delta = 405 - 135 = 270 test 4 s = 45, e = 135, ccw = true delta = 135 - 45 = 90 For CCW turns out. Now for CW test 1: s = 0, e = 90, ccw = false swap (s, e), ccw =! ccw e = 0 + 360 = 360 delta = 360 - 90 = 270 test 2: s = 90, e = 0, On absolute values converges, but it is necessary to place at result a sign depending on ccw. We tell, here so: double calcAngleDelta (double s, double e, bool ccw) {if (ccw) {if (e <s) e + = 360.0; return e - s;} return - calcAngleDelta (e, s, true);} For ccw there will be the positive increment, for cw - negative.

5

Re: It was tangled in three corners, mathematicians, help

6

Re: It was tangled in three corners, mathematicians, help

Hello, Marty, you wrote: M> [cut=] [ccode] inline M> double calcAngleDelta_StanislavVZudinV01 (double s, double e, bool ccw) M> {M> if (ccw) M> {M> if (e <s) M> e + = 360.0; M> return e - s; M>} M> return (here you forgot a minus) calcAngleDelta_StanislavVZudinV01 (e, s, true); M>} M> I also speak - lost the way in three corners the Mistake in one sign

7

Re: It was tangled in three corners, mathematicians, help

8

Re: It was tangled in three corners, mathematicians, help

Hello, Marty, you wrote: DR>> Select one direction of bypass both a corresponding initial and finite corner, calculate a difference on 360 unit, then add a sign corresponding to a direction. DR>> sector: 90 - 30 = 60 mod 360 DR>> a circle without sector: 30 - 90 = 300 mod 360 DR>> all converges M> So that and at me all converges, when I eyes see and intuitively I understand that from what it is necessary to take away, and that with what to add. A problem with algorithm. M> and a devil - it in details, as it is known. M> it is good - selected CW for example. M> how to select a corresponding initial and finite corner? #include <cmath> #include <iostream> using namespace std; double calcAngleDelta (double s, double e, bool ccw) {if (! ccw) swap (s, e); double delta = fmod (360.0 + e - s, 360.0); return ccw?-delta: delta;} int main () {cout <<calcAngleDelta (90.0, 30.0, false) <<'\n ';//60 cout <<calcAngleDelta (30.0, 90.0, false) <<'\n ';//300 cout <<calcAngleDelta (90.0, 30.0, true) <<'\n ';//-300 cout <<calcAngleDelta (30.0, 90.0, true) <<'\n ';//-60 return 0;}