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

You are not logged in.

## #26 2014-01-21 04:21:37

phrontister
Real Member

Offline

### Re: angle between points of a line

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

## #27 2014-01-21 05:36:11

bob bundy
Moderator

Offline

### Re: angle between points of a line

#### 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

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

## #28 2014-01-21 10:45:31

phrontister
Real Member

Offline

### Re: angle between points of a line

#### 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-21 11: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

## #29 2014-01-21 12:02:13

bob bundy
Moderator

Offline

### Re: angle between points of a line

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

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

## #30 2014-01-21 19:52:03

pari_alf
Member

Offline

### Re: angle between points of a line

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-21 19:57:38)

## #31 2014-01-21 21:24:12

bob bundy
Moderator

Offline

### Re: angle between points of a line

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-21 21:30:06)

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

## #32 2014-01-21 21:53:02

pari_alf
Member

Offline

### Re: angle between points of a line

#### 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
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

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

## #33 2014-02-03 13:21:52

pari_alf
Member

Offline

### Re: angle between points of a line

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.

## #34 2014-02-04 05:48:18

bob bundy
Moderator

Offline

### Re: angle between points of a line

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

## #35 2014-02-04 22:35:44

pari_alf
Member

Offline

### Re: angle between points of a line

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

## #36 2014-02-05 00:27:51

bob bundy
Moderator

Offline

### Re: angle between points of a line

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

## #37 2014-02-06 19:33:56

pari_alf
Member

Offline

### Re: angle between points of a line

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-06 19:46:42)

## #38 2014-02-07 02:32:34

bob bundy
Moderator

Offline

### Re: angle between points of a line

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

## #39 2014-02-20 23:30:44

pari_alf
Member

Offline

### Re: angle between points of a line

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 23:41:44)

## #40 2014-02-21 05:35:42

bob bundy
Moderator

Offline

### Re: angle between points of a line

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

## #41 2014-02-21 13:04:55

pari_alf
Member

Offline

### Re: angle between points of a line

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-21 13:06:37)

## #42 2014-02-21 19:23:50

bob bundy
Moderator

Offline

### Re: angle between points of a line

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

## #43 2014-04-09 12:46:01

pari_alf
Member

Offline

### Re: angle between points of a line

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-09 12:48:19)

## #44 2014-04-09 18:11:13

bob bundy
Moderator

Offline

### Re: angle between points of a line

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

## #45 2014-04-11 16:20:44

pari_alf
Member

Offline

### Re: angle between points of a line

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-11 18:43:56)

## #46 2014-04-12 00:27:34

phrontister
Real Member

Offline

### Re: angle between points of a line

Hi;

It's been so long since I last followed this thread that I'd forgotten some of it. Anyway, I reread some posts and here's what I've come to understand about the angle measurements...

Using points A and B (for example), along with X (a fictitious point to the right of A along A's x-axis), for a shape with starting point A, measure ∠XAB. The value is negative if A's y-axis value is less than B's.

I've also entered the points and angles from post #43 into Geogebra, and the image shows how a point's angle relates to the point's x-axis and the next point's bearing. However, I can't get it to identify the negative values - which maybe it can't do except by way of drawing the reflex angle (Geogebra's default setting for angles gives the reflex angle if points are selected in anticlockwise order).

Some angles are too small to show up properly in the image.

Points P16 to P33 make the exact shape of the character in posts #43's image, but there seems to be a point missing from the list in that post...the point for the left-hand end. I think the missing point is at approx (43,314).

Last edited by phrontister (2014-04-12 01:26:03)

"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

## #47 2014-04-12 01:25:46

phrontister
Real Member

Offline

### Re: angle between points of a line

Hi Bob,

I did the following in Excel, and got exactly the same angle measurements as pari_alf's:
- Enter x and y values into columns, starting at A2 and B2 respectively;
- C3: =DEGREES(ATAN2(A3-A2,B3-B2))
- Copy C3 down the column

It all seems to take care of itself, with no adjustments necessary.

"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

## #48 2014-04-12 22:08:22

phrontister
Real Member

Offline

### Re: angle between points of a line

Hi pari_alf,

Are the directions used somehow like in orienteering? eg, a person starts at position A, travels nearly SSE to B, then heads approx. NNNW to C, turns around and goes nearly due south to D, changes course to a nearly WSW direction towards E and finally heads a little west of SW to their final destination at F.

If so, then this is now starting to make sense to me, and I've drawn a compass image to demonstrate an application:
- The pink lines are those from the points and drawing in post #6 (see notated copy below), and if you compare the direction of those pink lines against the ones in my image you'll see they're identical;
- The black-on-blue text are the Direction Codes pertaining to the pie shapes they're in;
- The coloured circles denote starting position and end goal for each leg of the journey:
- Green = each leg's starting position
- Yellow = intermediate leg's end goal
- Red = final destination
- The angles of the pink lines below the E-W line are reflex angles (ie, 360° minus the ATAN2 angle), and on the 360° compass give a nice and clear idea of each leg's bearing (well, to me, anyway).

However, the Direction Codes now become these:

A-B = 13
B-C = 5
C-D = 12
D-E = 10
E-F = 10

They're close to what you and Bob have been getting, but the calcs method would need just a bit of tweaking to get it to agree with what I've done. ie, if I'm right, of course.

"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

## #49 2014-04-12 22:42:59

phrontister
Real Member

Offline

### Re: angle between points of a line

Hi pari_alf,

I'm unsure about a couple of points regarding the Direction Codes and need some clarification so I can create accurate Excel formulas to give the right codes.

1. I know there are 16 divisions, but do you want them numbered 0 to 15 (as in the "8 direction code" image in post #39...see copied image below), or 1 to 16? Btw, I used the latter version in my image without thinking, because that seemed to be the natural option.

2. Do you want line directions that are multiples of 22.5 coded to assume the Direction Code of the sector before or after the common boundary where the two sectors meet? eg, if line C-D in my image pointed due south (ie, to 270°, which is a multiple of 22.5), which Direction Code should apply: 12 or 13?

"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

## #50 2014-04-15 01:14:25

phrontister
Real Member

Offline

### Re: angle between points of a line

Here is a chart of post #43's figures and my version (as per my recent posts)...for comparison to see where we differ, which may help to work out why we differ and where the errors are.