Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

Hi Bob,

I liked the visual explanations on some of the web sites...their rotation graphics spoke to me. Always was right into comics!

What's wrong with having the positive y axis downwards. Isn't that how it is for you in Oz all the time?

No, we have the positive y-axis upwards...ie, upwards, towards the sky. Well, that's how it is on my monitor. Of course, if I printed out Geogebra's y-axis and laid the piece of paper on the desk, the positive bit would be neither upwards nor downwards, but sidewards. And that's a fact.

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,548

Phrontister wrote:

the positive bit would be neither upwards nor downwards, but sidewards.

That's funny. When I try that, the y+ axis is forward for me not sideways.

Bob

Children are not defined by school ...........The Fonz

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

bob bundy wrote:

That's funny. When I try that, the y+ axis is forward for me not sideways.

Well, I was taking it rather easy at the time of writing that post - as you can see from my self-portrait - and so for me the y-axis *was *sidewards to my body's orientation. However, I had the y+ axis pointing towards me (instead of forwards away from me) to better visualise the unusual orientation....and so that the writing on the page wasn't downside-up (although I can manage reading that way, though slowly; but sometimes by the time I've read right through to the end of a line I've forgotten what the beginning was about...which is happening to me more frequently with reading writing that is the right way up as I approach 29 ).

*Last edited by phrontister (2014-01-20 12:03:47)*

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,548

hi phrontister,

Old age getting the better of you? I don't think so! Now I am positively ancient as that picture above shows. If you look carefully at the desk you can see the ink well where I dip my quill to write my posts.

Bob

Children are not defined by school ...........The Fonz

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**pari_alf****Member**- Registered: 2013-12-01
- Posts: 85

Hi all,

ok As we have seen that angle is correct of all points.

Well the purpose of computing angle is to assign the 16 direction code for each line direction.

Since a circle circle is made up with 360 angles.

To get the 16 direction code for angles or direction of line, what we are doing is something like this ...

directionCode = ( angle / 22.5 ) - 16 , if angle is positive

else directionCode = (angle / 22.5) + 16, if angle is negative.

Since we need to get 16 direction Codes of angles.

so total angles 360 / 16 = 22.5 .

ok.. The problem i have with angle of Point B to C is that i got direction code 11, that meant the direction of line is downward. while the image attached in my post #6 shows that the line direction is from B to C that is upward direction .. therefore according to my figure in #6, direction code should 4 or 3.

A figure of direction code in circles are shown like this.

you can assign direction like this .. .

E = 0

between E and N, we have direction code 1 , 2 , 3

N = 4

between N to W, we have direction code 5 ,6 , 7

W = 8

between W to S, we have direction Code 9, 10, 11

S = 12

between S to E , we have direction code 13, 14 , 15

and finally east = 16.

So, the angle from point B to C, gives me direction code 11.

which is wrong. because the line shows its direction to upward in my attached figure of post #6.

That'sy i am not satisfy with the angle of B to C. that's y, I am saying that my angle is inverted.

One more thing, that an image don't have negative x or y values. then how can i put the y values as negative to make the angle of point B to C to the upward direction.

or i should change my method of angle computation?

*Last edited by pari_alf (2014-01-20 20:57:38)*

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,548

hi pari_alf

So you wish to convert those angles into numbers from 0 to 15 according to the diagram below.

Step 1. Take the calculated angles

result

70 .9...

-97.0....

92.3....

155.0...

144.7....

step 2. Divide each by 22.5

result

3.15..

-4.31..

4.10..

6.89..

6.43..

step 3. Add 0.5 so that when I use INT I will round up or down correctly

result

3.65..

-3.81..

4.60..

7.39..

6.93..

step 4. take the integer part of (note that the negative goes to -4 with my software)

result

3

-4

4

7

6

step5. Subtract from 16 to get the correct rotational direction

result

13

20

12

9

10

step6. use mod 16 division to get the numbers in range

result

13

4

12

9

10

And there you have it. I suggest you check boundary cases such as angle = 90 in case these misbehave.

Bob

*Last edited by bob bundy (2014-01-20 22:30:06)*

Children are not defined by school ...........The Fonz

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**pari_alf****Member**- Registered: 2013-12-01
- Posts: 85

bob bundy wrote:

hi pari_alf

So you wish to convert those angles into numbers from 0 to 15 according to the diagram below.

Step 1. Take the calculated angles

result

70 .9...

-97.0....

92.3....

155.0...

144.7....step 2. Divide each by 22.5

result

3.15..

-4.31..

4.10..

6.89..

6.43..step 3. Add 0.5 so that when I use INT I will round up or down correctly

result

3.65..

-3.81..

4.60..

7.39..

6.93..step 4. take the integer part of (note that the negative goes to -4 with my software)

result

3

-4

4

7

6step5. Subtract from 16 to get the correct rotational direction

result

13

20

12

9

10step6. use mod 16 division to get the numbers in range

result

13

4

12

9

10And there you have it. I suggest you check boundary cases such as angle = 90 in case these misbehave.

Bob

ahhan .. i see .. thank you a lot Bob and phrontister..

Offline

**pari_alf****Member**- Registered: 2013-12-01
- Posts: 85

Hi bob,

I wanna show one example.. and its directional code for 0 direction is not appropriate..

The example is shown in the attached image.

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,548

hi

I did say

I suggest you check boundary cases such as angle = 90 in case these misbehave.

I cannot read the coordinates but I guess you were expecting a horizontal line to come out with a zero and it hasn't.

Do you know how to do a 'dry run' ?

You set up columns, one for each variable, and then work your way through the code, line by line, writing in the values working the sums 'by hand'.

This should show up where an adjustment is needed to the code. It may just be a matter of changing a < into ≤ or something similar.

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**pari_alf****Member**- Registered: 2013-12-01
- Posts: 85

ahhhan ok..

you meant there would be a problem in the code.. so i should check execution using breakpoints.

ok ok.. i will come back soon with good report

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,548

Sounds like a good plan.

You want a number from 0 to 11. atan2 returns an angle on a continuous basis but changes the calculation as the line moves from quadrant to quadrant. When changing from continuous to discrete there is always a risk of the code going 'wrong' at the discrete changeover points.

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**pari_alf****Member**- Registered: 2013-12-01
- Posts: 85

ahhan .. ok ..

but Can you suggest me any method to verify the Code of each line segment?

thanks

*Last edited by pari_alf (2014-02-05 20:46:42)*

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,548

This is what a 'dry run' will do.

You check your code by doing the 'sums' yourself and test out why you are getting an unexpected result.

Try coordinates that will make a horizontal line eg. (10,10) and (20,10)

What is atan2 for that? and what number do you get from 0 to 11 ?

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**pari_alf****Member**- Registered: 2013-12-01
- Posts: 85

Hi again,

This time i came here with a formula for calculating angle (which i found in one paper)

The formula is as shown below.

I tested that on the following points

@ 0(105, 66)

@ 1(114, 92)

@ 2(104, 11)

@ 3(99, 131)

@ 4(71, 144)

@ 5(37, 168)

These points are down on the image like this ..

and these are the angles

Angle : 5.0469

Angle : 1.6949

Angle : 4.67201

Angle : 3.57753

Angle : 3.75752

Then i assigned the 8 directional code to each angle using this formula

d = (( (int) ( (8 * angle) / pi) + 1) mod 16 ) /2 ------------- (found in paper)

0

4

5

5

2

The 8 direction Code is shown in the attached file (found in paper)

I do't understand these angles and 8 directional code.

It seems not correct,.

or I am not implementing correctly.

If anyone can verify me then it would be easy for me to understand the paper.

Thanks

*Last edited by pari_alf (2014-02-20 00:41:44)*

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,548

hi pari_alf

I've had a look at this but I have many questions.

(i) I cannot read the formula screen shot properly. It's too small and if I zoom it up then the resolution is very poor. Please would you try this again.

(ii) I cannot relate the coordinates to the angles. How did you get from one to the other?

(iii) The 'd' formula has at least one error in it as it has more open brackets than close brackets.

(iv) The directions don't seem to relate to the angles at all. 3.57753 and 3.75752 are close to each other but the directions, 5 and 2, are far apart, so something is definitely wrong here.

If you can improve the quality of the formula screen shot and explain point (ii) I can probably work out (iii) and hence correct (iv)

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**pari_alf****Member**- Registered: 2013-12-01
- Posts: 85

ok The formula is as shown below

I am using the same points which i used to solve my first problem i posted in this post.

In my this post, i posted these points and angle using atan2 (dy ,dx) method

@ 0(105, 66)

@ 1(114, 92)

@ 2(104, 11)

@ 3(99, 131)

@ 4(71, 144)

@ 5(37, 168)

angle : 70.9065

angle : -97.0379

angle : 92.3859

angle : 155.095

angle : 144.782

But now i am just testing the angle calculating formula taken from one paper, attached in this post.

And i got these angles

Angle : 5.0469

Angle : 1.6949

Angle : 4.67201

Angle : 3.57753

Angle : 3.75752

I also don't understand the angle with those points.

*Last edited by pari_alf (2014-02-20 14:06:37)*

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,548

hi pari_alf

Thanks, I can read that perfectly. I'm still puzzled as I don't know what the paper means by cx, pt[i], and r[i]

But I can see how this should work. Instead of using atan2 to calculate angles the paper is using acos. This requires a calculation of the hypotenuse using Pythagoras. As with atan, the angle will be in the 'principle angle' range and the PI + sign part is just a correction to get the angle needed on the graph.

No idea why you get incorrect angles; I got 4.379145.... rather than 5.0469 (value in radians) so I suspect there's something funny with your code. Post that if you want and I'll take a look. Or you could just stick with the previous version which works!!!

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**pari_alf****Member**- Registered: 2013-12-01
- Posts: 85

I have this image

I have these points of the above drawn character

x: 126, y: 279

x: 172, y: 257

x: 209, y: 238

x: 247, y: 230

x: 271, y: 225

x: 249, y: 334

x: 228, y: 369

x: 193, y: 383

x: 122, y: 411

x: 64, y: 439

x: 79, y: 451

x: 128, y: 449

x: 191, y: 416

x: 240, y: 376

x: 264, y: 358

x: 279, y: 343

x: 86, y: 270

x: 110, y: 256

x: 133, y: 246

x: 169, y: 248

x: 199, y: 250

x: 197, y: 273

x: 193, y: 304

x: 182, y: 334

x: 161, y: 366

x: 146, y: 397

x: 143, y: 419

x: 146, y: 434

x: 160, y: 443

x: 185, y: 420

x: 219, y: 390

x: 247, y: 366

x: 289, y: 343

x: 327, y: 340

-----------

and these are the angles computed by atan2 in degree form

@ 0 , Angle: -25.56

@ 1 , Angle: -27.1811

@ 2 , Angle: -11.8887

@ 3 , Angle: -11.7683

@ 4 , Angle: 101.411

@ 5 , Angle: 120.964

@ 6 , Angle: 158.199

@ 7 , Angle: 158.477

@ 8 , Angle: 154.231

@ 9 , Angle: 38.6598

@ 10 , Angle: -2.33731

@ 11 , Angle: -27.646

@ 12 , Angle: -39.2257

@ 13 , Angle: -36.8699

@ 14 , Angle: -45

@ 15 , Angle: -159.281

@ 16 , Angle: -30.2564

@ 17 , Angle: -23.4986

@ 18 , Angle: 3.17983

@ 19 , Angle: 3.81407

@ 20 , Angle: 94.9697

@ 21 , Angle: 97.3524

@ 22 , Angle: 110.136

@ 23 , Angle: 123.275

@ 24 , Angle: 115.821

@ 25 , Angle: 97.7652

@ 26 , Angle: 78.6901

@ 27 , Angle: 32.7352

@ 28 , Angle: -42.6141

@ 29 , Angle: -41.4237

@ 30 , Angle: -40.6013

@ 31 , Angle: -28.706

@ 32 , Angle: -4.51399

---------------

and these are the direction codes.

@ 0 : 1

@ 1 : 1

@ 2 : 1

@ 3 : 1

@ 4 : 12

@ 5 : 12

@ 6 : 10

@ 7 : 10

@ 8 : 10

@ 9 : 15

@ 10 : 0

@ 11 : 1

@ 12 : 2

@ 13 : 2

@ 14 : 2

@ 15 : 7

@ 16 : 1

@ 17 : 1

@ 18 : 0

@ 19 : 0

@ 20 : 13

@ 21 : 13

@ 22 : 12

@ 23 : 12

@ 24 : 12

@ 25 : 13

@ 26 : 14

@ 27 : 0

@ 28 : 2

@ 29 : 2

@ 30 : 2

@ 31 : 1

@ 32 : 0

----------------

I am not satisfy with my direction numbers to each angle.

Anyone help me to check it. thanks

*Last edited by pari_alf (2014-04-08 14:48:19)*

Offline

**bob bundy****Moderator**- Registered: 2010-06-20
- Posts: 7,548

hi pari_alf

I copied your text into an Excel spreadsheet to save having to re-type everything. If you post data again, it would help if you left out all unneeded text and just gave me the numbers.

eg.

x values are

126

172

209

etc

then I can copy these straight in rather than having to "MID" out the unwanted characters. Thanks.

Excel's atan works slightly differently to your program language so I got some different angles. In the screen shot below I have highlighted these in yellow.

I applied the correction 180 - yellow value and in all but one case that corrected the error. That's probably not something to worry about; it is just the way the software writers have implemented the function.

The one remaining difference is with - 159.281 I don't know why that one is still different. But our direction codes are the same!

You haven't said how you converted these to direction codes, so I went back to my post 31 and applied those steps. For values up to direction code 7, we have the same results. Thereafter, my answers are 1 less than yours. And I get 15 not zero for 32.7.... I'd need to see the code to explain that. It may be something to do with the way the numbers are rounded.

Please also give the exact start and end angles for the sectors ; then I can modify the steps to account for the differences.

eg.

sector 0: 0 ≤ angle < 22.5

Bob

You cannot teach a man anything; you can only help him find it within himself..........Galileo Galilei

Offline

**pari_alf****Member**- Registered: 2013-12-01
- Posts: 85

Hi Bob,

hmm frankly speaking, those direction Codes are not matched with the direction of lines of the points of character drawn on the image. So i am still not satisfied.

Yes i used the same steps that you gave in post 31.

*Last edited by pari_alf (2014-04-10 20:43:56)*

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

Hi pari_alf

pari_alf wrote:

Yes i used the same steps that you gave in post 31.

Using those steps of Bob's on your coordinates from post #43 I got the following direction codes ("DC"), which I've written alongside yours for comparison:

```
Line your DC my DC
@ 0 1 1
@ 1 1 1
@ 2 1 1
@ 3 1 1
@ 4 12 11
@ 5 12 11
@ 6 10 9
@ 7 10 9
@ 8 10 9
@ 9 15 14
@ 10 0 0
@ 11 1 1
@ 12 2 2
@ 13 2 2
@ 14 2 2
@ 15 7 7
@ 16 1 1
@ 17 1 1
@ 18 0 0
@ 19 0 0
@ 20 13 12
@ 21 13 12
@ 22 12 11
@ 23 12 11
@ 24 12 11
@ 25 13 12
@ 26 14 13
@ 27 0 15
@ 28 2 2
@ 29 2 2
@ 30 2 2
@ 31 1 1
@ 32 0 0
```

There are 14 differences between your results and mine, so there's a coding error somewhere...

To verify my results I used a different method to check my DCs and got exactly the same answers as with Bob's formula.

My method calculates the actual line directions based on an anticlockwise 360° compass with origin E=0° (as per your post #30). This also gives me a clearer idea of each line's bearing than I was getting from just knowing a line's angle (ie, the angle measured from (a) the horizontal axis of a line's starting point to (b) the next point: this is what the angles listed in your post #43 actually represent). Your angles are correct, btw...according to Geogebra and ATan2 in Excel.

pari_alf wrote:

those direction Codes are not matched with the direction of lines of the points of character drawn on the image. So i am still not satisfied.

I've drawn a compass (see image) in Geogebra with angle markings and DCs that follow your method (see post #30). Upward angles are negative (and run anticlockwise), and downward angles are positive (and run clockwise). There are 16 sectors, all with an angle range of 22.5°. They run anticlockwise, with the first one (DC=0) straddling E=0°.

With this image I can easily determine a line's DC from seeing where the line lies on the compass. I did that with all the lines, and got identical DCs to what I got with Bob's formula.

Lines placed on the compass should originate at the crosshair in the centre and from there radiate out to their angle locations at the compass perimeter. The sectors on which the lines lie display the respective DCs in the white-on-blue rectangles.

If you'll use the compass to check the direction of the lines where our DCs differ you'll see that your lines lie in the wrong DC sector...as follows:

```
Line angle DC sector angle range correct DC your DC
@ 4 101.411 101.25 to 123.75 11 12
@ 5 120.964 101.25 to 123.75 11 12
@ 6 158.199 146.25 to 168.75 9 10
@ 7 158.477 146.25 to 168.75 9 10
@ 8 154.231 146.25 to 168.75 9 10
@ 9 38.6598 33.75 to 56.25 14 15
@ 20 94.9697 78.75 to 101.25 12 13
@ 21 97.3524 78.75 to 101.25 12 13
@ 22 110.136 101.25 to 123.75 11 12
@ 23 123.275 101.25 to 123.75 11 12
@ 24 115.821 101.25 to 123.75 11 12
@ 25 97.7652 78.75 to 101.25 12 13
@ 26 78.6901 56.25 to 78.75 13 14
@ 27 32.7352 11.25 to 33.75 15 0
```

Btw, you haven't yet cleared up the question of 'boundary cases' that Bob mentioned in post #31. Which DC should be given to a line that falls exactly on a DC boundary?

*EDIT: I've just noticed that all those errors (which are out by +1) are for downward lines (ie, those with a positive angle), and the only downward lines for which you got correct DCs are lines @18 and @19. The DCs for all your upward lines (ie, those with a negative angle) are correct.*

Note: You may need to zoom out in your browser to see the whole image (this happened with the forum upgrade).

*Last edited by phrontister (2014-05-28 16:01:52)*

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 103,772

Hi;

Just let me say that is a beautiful use of geogebra. Wunderbar!

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.** **A number by itself is useful, but it is far more useful to know how accurate or certain that number is.**

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

Thanks!

Geogebra gave the necessary graphical accuracy I needed (and quite quickly, too), as three of the angles (@ 4, @ 23 and @ 26) are extremely close to the Direction Code boundaries and would be difficult to locate correctly by superimposition on a less accurate drawing.

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

I've rewritten my post #46 to try and make it clearer, as I felt after rereading it that it needed a good overhaul.

*Last edited by phrontister (2014-05-08 14:08:44)*

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

Here's an image of my Excel worksheet, including formulas.

Notes: 1. The upward angles display as positive values in Geogebra and not negative (unlike with ATan2).

2. You may need to zoom out in your browser to see the whole image (this happened with the forum upgrade).

*Last edited by phrontister (2014-05-28 16:09:13)*

Offline