Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: √ ∞ ≠ ≤ ≥ ≈ ⇒ ∈ Δ θ ∴ ∑ ∫ π -

Login

Username

Password

Not registered yet?

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

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

No, we have the positive y-axis upwards...ie, upwards, towards the sky. shame 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.  smile

Bob


Uploaded Images
View Image: y direction.gif      


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.  smile

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 sad ).


Uploaded Images
View Image: At Desk.jpg      

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


Uploaded Images
View Image: quill and well.gif      


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.

http://s29.postimg.org/mz2bat0ur/encompass.png
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


Uploaded Images
View Image: pari alf5.gif      

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.. smile

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

http://s27.postimg.org/muu5uydlb/exam_of_direction_Code.jpg

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

#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.
http://s24.postimg.org/7q7zhlzc1/calculating_angle.jpg]
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 ..

http://s11.postimg.org/5hkt0iszj/drawing_image.jpg]

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)
http://s29.postimg.org/mj1d0jucz/8_direction_code.jpg]


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

http://s8.postimg.org/kosstirid/calculating_angle.png

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

http://s28.postimg.org/3saqkckwt/img.png

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


Uploaded Images
View Image: pari2.gif      


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


Uploaded Images
View Image: Excel.png      


"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

Board footer

Powered by FluxBB