Circles

General FreeBASIC programming questions.
Locked
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Post by albert »

Thanks Bemptier!!

I'll keep at it until i come up with something!

I think that 16 places of sin() and cos() with the normalization will cover it.

Although at .5 step the 15 place circle looks better than the 16 place circle.
but at 1 step the 16 place circle looks better than the 15 place circle.
And both look better than the 17,18 or 19 place circles.(which have big gaps).
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Post by Richard »

Thank you all for your kind words. I see no reason why the FB forum should not be both educational and entertaining. I think this topic is titled “Circles” because we are dancing round in them, I'm trying to keep them spiralling outwards through the door and all round the graveyard of numerical mathematics. I could really do with an assistant to help me mix my metaphors, how close to the wind can I sail, and still have water run of the ducks back. Maybe the duck is a decoy made of wax.

I have not had time to understand Albert's vector geometry yet. Could someone (bfuller?) take a closer look at this for Albert.
if you take a square and draw a line through it from corner to corner top right to bottom left and draw a line at 23.5 degrees from bottom right, it crosses the 45 degree line at 2.92894 from the right and .707106 from the left.
(180 - 45 = 135 * .5 = 67.5 | 90 - 67.5 = 23.5)
There has to be another way to figure the intersection other than powering and dividing by the factorial. The formula just hasn't been invented yet. (I'm working on inventing it!)
I think the 23.5 degrees might refer to the “obliquity of the ecliptic” and that this is a navigational or astronometric problem. Might the Haversine be applicable? http://en.wikipedia.org/wiki/Haversine_formula
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Post by albert »

@Richard

The 23.5 is the opposing angle of 45 degrees
180 - 45 = 135
135 / 2 = 67.5 degrees from the horizontal.

90 - 67.5 = 23.5 degrees from the vertical.

When you take a degree angle the opposite angle is 180 - degree / 2 as The opposite angle has two macthing degrees.
And the three degreees add up to 180.

Its true for circle angles anyways.


so! If you draw a line from xctr,yctr at the degree vector and draw another line from radius , yctr at the opposite vector the two intersect at the cosine,sine.


With your math knowledge you probably already know that, its just the way i worded the thing that threw you off.
bfuller
Posts: 362
Joined: Jun 02, 2007 12:35
Location: Sydney, Australia

Post by bfuller »

90 minus 67.5 is NOT 23.5

90 minus 67.5 equals 22.5 which happens to be half of 45!

67.5 is half of 135 (which is 90+45)

and 0.707106 is 1/(sqrt 2) or sqrt(0.5). This is to be expected for a 45 degree right triangle. Cos (45) is 0.707106 as well--phew!

I have so far been unable to work out where 2.92894 came from. I think it should be 1.707

Image

Albert, I suggest you try to draw your problem. If I understand what you are trying to portray, then see above. If the intersection is 0.707 from the left, then the distance "x" must be 1.707 from the right

What are we trying to achieve here?

Perhaps you are right Richard, we may be on a sphere and doing great circle navigation, where a triangle can have more that 180 degrees but lets not try to explain that in this thread.
Last edited by bfuller on Dec 07, 2009 1:57, edited 1 time in total.
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Post by albert »

The .292894 is the opposite of .707106 (sqr.5)

1 = sqr(.5) = .292894.......

if you draw a line from radius, ycenter(0) to 1 at 67.5 degrees it intersects the 45 degree line at .292894 from the vertical.

90 - 67.5 is 22.5 and not 23.5 sorry!!! about the screw-up.

in a circle the other two angles oppsite from the degree angle are identical angles.

somehow there is a way to rotate around the circle by using the angle length of 1 degree which is .01745.... something. and using the tangent to keep the distance equal between steps. but i can't remember how i did it.
its a formula similar to solving a chord length but opposite.
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Post by albert »

I found a way to minimize the errors in the sin() and cos() where they make gaps in the line segments of the circle.

Check this good looking circle out. (I cheated! I found out that the mag can be used to correct the gaps in the circle. )

Code: Select all

'================================================================
'  approximations measured relative to the reference circle ... blue
Const As Double mag = 10000000000000  ' magnification of errors
'================================================================
Dim As Double t, tt, grad, q, s, c, dx, dy, x, y, r = 1.1
Dim As Double sqrt

Screen 19
Dim As Integer w, h, depth
Screeninfo w, h, depth
Window (-r * w / h, -r) - (r * w / h, r)  ' maintain pixel aspect

'----------------------------------------------------------------
Line(-c, 0)-(c, 0), 1   ' x axis
Line(0, -c)-(0, c), 1   ' y axis
Const As Double Pion2 = 2 * Atn(1)
For t = 0 To 4 * Pion2 Step Pion2 / 1000
    x = Cos(t)
    y = Sin(t)
    Pset(x, y), 1       ' reference circle
    Pset(x*.1, y*.1), 1 ' one tenth of circle at centre
Next t

'============================================================
'============================================================
dim as string sine,cosine
For grad = 0 To 90 step 1
    
    c = cos(grad*(pion2/90))
    s = sin(grad*(pion2/90))
    
    if c<0 then c=0
    if s<0 then s=0

    cosine = left(str(c),16)
    sine =   left(str(s),16)

    c=val(cosine)
    s=val(sine)

    sqrt=sqr((c*c)+(s*s))
    c=c/sqrt
    s=s/sqrt

'----------------------------------------
    r = 1 + mag * (Sqr(c*c + s*s) - 1)   ' magnify radius error
    c = c * r
    s = s * r
    x=c
    y=s
    Pset (+x, -y), 10
    Pset (+x, +y), 10
    Pset (-x, -y), 10
    Pset (-x, +y), 10
    line(0,0)-(+x, +y), 10
    line(0,0)-(+x, -y), 10
    line(0,0)-(-x, +y), 10
    line(0,0)-(-x, -y), 10
    'print atan2(s,c)*90/pion2
    'print x,c; " - " ; y,s
    dx = c - Cos(grad*(pion2/90))
    dy = s - Sin(grad*(pion2/90))
    Circle(mag * dx, mag * dy), 0.01, 12   ' plot the scatter
Next grad
'================================================================
Sleep
'================================================================
 
it looks better than the plain sin(),cos() circle and no gaps around 35 ,55 degrees.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Post by Richard »

@Albert.
its a formula similar to solving a chord length but opposite.
Maybe you should call it CHORDIC.
That should not add too much to the confusion.
bfuller
Posts: 362
Joined: Jun 02, 2007 12:35
Location: Sydney, Australia

Post by bfuller »

Ah, now I see what you have done. You meant .292, not 2.92 etc you really need to double and tripple check for typing errors before hitting the submit button, especially when dealing with precise numbers.
The .292894 is the opposite of .707106 (sqr.5)

1 = sqr(.5) = .292894.......
you mean .292894 is 1 minus sqr(.5) not "=".

As I said above, I suggest you try to draw what want to do.

Now with a different diagram, yes I can see how you got 0.292

Image

and because we have a 45degree line, that intersection point is also .292 down from the top of the square.
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Post by albert »

I'm starting to remember some things, keep it up! you guys are helping me refresh my memory some.


I used to have a book called "Vector Analysis" My dad bought me when i was interested in taking flying lessons, And i adapted some of the formulas from that book to get my lines rotation for my drawing program.


The opposite angle is always half the degree angle and the intersection is always a percentage (I forget what percentage.) of the the angles.

Maybe you guys can help figure out the percentage for me since i really suck at math. (But, The percentage, its the same for every degree.)
bfuller
Posts: 362
Joined: Jun 02, 2007 12:35
Location: Sydney, Australia

Post by bfuller »

Albert, try making some drawings of what you want for a few different angles. Post them.
The percentage, its the same for every degree
I think you will find that this is not really true for every angle because we do not have a linear function here in a circle. That's the knub of the issue.

In my diagram, the diagonal of the square is sqr(2) or 1.414, so the little top right bit of the diagonal left over is 0.414, divide that by sqr(2) or multiply by 0.707 and you have 0.29289, the side of the little square that would be in the top right corner of my box had I drawn it there. This only works because it is a square and the diagonal is 45 degrees. At other angles you have to use tigonometry, not sqr(2) to get the correct answer. For instance, at 30/60/90 triangle, the ratio is 0.866 or sqr(3)/2 (not 0.707).

We might be getting a bit off the track here, and I'm not sure I know what you mean by
the intersection is always a percentage (I forget what percentage.) of the the angles
but I doubt that
its the same for every degree
I repeat myself, but we are not dealing with linear functions.
Richard
Posts: 3096
Joined: Jan 15, 2007 20:44
Location: Australia

Post by Richard »

Prior to GPS, navigation relied on a “One in 60 Rule” that said if you change your course by one degree you will change your way by 1 mile in 60 miles, it also held that a change of 2 degrees would make a difference of 2 miles in 60 (or 1 mile in 30). The rule only works for small angles when correcting for magnetic compass variation, cross currents or winds while navigating. It is quick but not mathematically precise.
Tan(1 deg) = 0.017455 = 1 / 57.2899 which is where the crude navigation 1 in 60 rule comes from.
The slope of the Tan function at zero is 1 unit per radian, which is 1 in 180/Pi degrees.
That equals 1 in 57.2957795 , the conversion between radians and degrees.
See http://en.wikipedia.org/wiki/1_in_60_rule
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Post by albert »

the ratios are 1 to .5 to .25

which gives you an increment of 1.5 when adding the two vectors.

the degrees increment by 1, the opposite angle decrements by .5 and the opposite of the opposite decrements by .25 or half the opposite, its always a 1 to .5 ratio.

The intersection is always a quater of the degree. one/half/quater.

at 45 degrees the opposite is 22.5 and the opposite of the opposite is 11.25 (1/.5/.25) degrees which is the intersecting angle.
45 degrees is .7853.... so you make a line at .7853 and the actual value or sine , is a line drawn at 11.25 degrees from the .7853.

I think the value is 90 + (1.5*deg/10) or 96.75 for 45 degrees, i think you divide the combined vectors (67.5) by the 96.75 and it equals .70....
It might be 90 + 1/8. so it might be 90 + 5.625 or 67.5 / 95.625
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Post by albert »

Forget it! it doesn't work, the degrees marks are wide around 45 degrees.

I tried 90+1/8 and it didn't work so good so i tried 90 + grad/8.75 and it worked a little better but i could only get a magnification of 1.

Code: Select all

'================================================================
'  approximations measured relative to the reference circle ... blue
Const As Double mag = 1  ' magnification of errors
'================================================================
Dim As Double t, tt, grad, q, s, c, dx, dy, x, y, r = 1.1
Dim As Double sqrt

Screen 19
Dim As Integer w, h, depth
Screeninfo w, h, depth
Window (-r * w / h, -r) - (r * w / h, r)  ' maintain pixel aspect

'----------------------------------------------------------------
Line(-c, 0)-(c, 0), 1   ' x axis
Line(0, -c)-(0, c), 1   ' y axis
Const As Double Pion2 = 2 * Atn(1)
For t = 0 To 4 * Pion2 Step Pion2 / 1000
    x = Cos(t)
    y = Sin(t)
    Pset(x, y), 1       ' reference circle
    Pset(x*.1, y*.1), 1 ' one tenth of circle at centre
Next t

'=============================================================
'=============================================================
For grad = 0 To 90 Step 1
    
    if grad <=45 then 
        s=( (grad*1.5) / (90+(grad/8.75)) )
        c=sqr(1-s*s)
    else
        c=( ((90-grad)*1.5) / (90+((90-grad)/8.75)) )
        s=sqr(1-c*c)
    end if

'----------------------------------------
    r = 1 + mag * (Sqr(c*c + s*s) - 1)   ' magnify radius error
    x = c * r
    y = s * r
    Pset (+x, -y), 10
    Pset (+x, +y), 10
    Pset (-x, -y), 10
    Pset (-x, +y), 10
    line(0,0)-(+x,-y),14
    line(0,0)-(+x, y),14
    line(0,0)-(-x,-y),14
    line(0,0)-(-x, y),14
    'print atan2(s,c)*100/pion2
    t = grad * Pion2 / 100
    dx = c - Cos(t)
    dy = s - Sin(t)
    Circle(mag * dx, mag * dy), 0.01, 10   ' plot the scatter
Next grad

'================================================================
Sleep
'================================================================ 

I think that why they keep the airplanes 2500 ft. apart because the formula is only good to .3 miles at 100 miles.
Last edited by albert on Dec 07, 2009 23:32, edited 1 time in total.
bfuller
Posts: 362
Joined: Jun 02, 2007 12:35
Location: Sydney, Australia

Post by bfuller »

I think Richard was correct earlier
Thanks Bemptier!!
you are a comedian at heart. Ha Ha.

and now
I think the value is 90 + (1.5*deg/10) or 96.75 for 45 degrees, i think you divide the combined vectors (67.5) by the 96.75 and it equals .70....
It might be 90 + 1/8. so it might be 90 + 5.625 or 67.5 / 95.625
you have surely proved him correct.

You have truly lost me i'm afraid.

Try drawing it please, at multiple angles.
albert
Posts: 6000
Joined: Sep 28, 2006 2:41
Location: California, USA

Post by albert »

I don't know how to put pictures on this message board.


Bu if you draw the degrees angle and the draw the opposite angle and draw a line accross the square at the height of the length of arc. the intersection of the degree angle and the opposite angle is 1/4 of the degree from the line you drew across.

angle = 1 deg | opposite angle = .5 deg | distance down from deg*radians = .25 deg

angle = 30 | opp angle = 15 | intersection = 30/4 or 7.5 deg down from deg*radians (PI/180*30)

==============================================
the combined angles divided by 90 + (deg/8) only works to .3 in 100, you get .704 instead of .707 at 45 degrees and you get .01664 intsead of .0174 at 1 deg
Locked