• Print

Author Topic: Circle not closing properly when using negative radians  (Read 248 times)

TerryRitchie

  • Hero Member
  • *****
  • Posts: 2264
  • FORMAT C:\ /Q /U /AUTOTEST (How to repair Win8)
    • Email
Circle not closing properly when using negative radians
« on: January 29, 2013, 12:13:38 PM »
Ok, I found yet another problem that I am hoping is a problem in my coding.

When using negative radians to create a line to go from the center of the circle to the radian angle, where the line meets the arc is not always closing properly.  In some instances the arc travels further than the line as well.  Here is some code I wrote to highlight the issues I am speaking of.

Use the SPACE BAR to change between the four different views to see this is in action.  Thanks for any help in advance.

Code: [Select]
'**
'** PacMan Ritchie Style! V1.0
'**

CONST FALSE = 0, TRUE = NOT FALSE
CONST MOUTHMOTION = 100

TYPE MOUTH
    StartRad AS SINGLE
    EndRad AS SINGLE
END TYPE

DIM Mouth(4, MOUTHMOTION - 1) AS MOUTH
DIM MouthIncrement!

MouthIncrement! = .78539815 / MOUTHMOTION

Mouth(1, 0).StartRad = -2.35619445 '  .75Pi
Mouth(1, 0).EndRad = -.78539815 '     .25Pi
Mouth(2, 0).StartRad = -.78539815 '   .25Pi
Mouth(2, 0).EndRad = -5.49778705 '   1.75Pi
Mouth(3, 0).StartRad = -5.49778705 ' 1.75Pi
Mouth(3, 0).EndRad = -3.92699075 '   1.25Pi
Mouth(4, 0).StartRad = -3.92699075 ' 1.25Pi
Mouth(4, 0).EndRad = -2.35619445 '    .75Pi

FOR Direction% = 1 TO 4
    FOR Position% = 1 TO MOUTHMOTION - 1
        Mouth(Direction%, Position%).StartRad = Mouth(Direction%, Position% - 1).StartRad + MouthIncrement!
        Mouth(Direction%, Position%).EndRad = Mouth(Direction%, Position% - 1).EndRad - MouthIncrement!
    NEXT Position%
NEXT Direction%

Direction% = 1
MouthCountDir% = 1

SCREEN _NEWIMAGE(640, 480, 32)
_SCREENMOVE _MIDDLE

DO
    _LIMIT 30
    CLS
    CIRCLE (319, 239), 200, _RGB32(255, 255, 0), Mouth(Direction%, MouthCount%).StartRad, Mouth(Direction%, MouthCount%).EndRad
    MouthCount% = MouthCount% + MouthCountDir%
    IF MouthCount% = MOUTHMOTION - 1 OR MouthCount% = 0 THEN MouthCountDir% = -MouthCountDir%
    a$ = INKEY$
    IF a$ = " " THEN
        Direction% = Direction% + 1
        IF Direction% = 5 THEN Direction% = 1
    END IF
    _DISPLAY
LOOP UNTIL a$ = CHR$(27)

Clippy

  • Hero Member
  • *****
  • Posts: 16445
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Circle not closing properly when using negative radians
« Reply #1 on: January 29, 2013, 01:32:37 PM »
It appears that the top and bottom ones are not connected. This would be a QB64 bug. PAINT won't like that!
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

TerryRitchie

  • Hero Member
  • *****
  • Posts: 2264
  • FORMAT C:\ /Q /U /AUTOTEST (How to repair Win8)
    • Email
Re: Circle not closing properly when using negative radians
« Reply #2 on: January 29, 2013, 02:11:05 PM »
Quote from: Clippy on January 29, 2013, 01:32:37 PM
It appears that the top and bottom ones are not connected. This would be a QB64 bug. PAINT won't like that!

Exactly, when I went to paint PacMan yellow that is when I noticed something wasn't right.  If this is a verified QB64 bug then I'll simply need to write a circle/arc/radian routine myself.  I just hope it's as fast as Galleon's CIRCLE command.

Clippy

  • Hero Member
  • *****
  • Posts: 16445
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Circle not closing properly when using negative radians
« Reply #3 on: January 29, 2013, 03:07:56 PM »
Please report just in case.
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

TerryRitchie

  • Hero Member
  • *****
  • Posts: 2264
  • FORMAT C:\ /Q /U /AUTOTEST (How to repair Win8)
    • Email
Re: Circle not closing properly when using negative radians
« Reply #4 on: January 29, 2013, 06:00:42 PM »
Well, from what I can tell this section is where a bug needs reporting. (Didn't there used to be a dedicated section?) So I guess when Galleon reads this he can confirm a bug or not.

OlDosLover

  • Hero Member
  • *****
  • Posts: 3860
  • OlDosLover
    • Email
Re: Circle not closing properly when using negative radians
« Reply #5 on: January 29, 2013, 06:48:11 PM »
Hi all,
    This is that section and it was moved on the main page downward thats all.
Quote
Well, from what I can tell this section is where a bug needs reporting. (Didn't there used to be a dedicated section?)
OlDosLover.

Clippy

  • Hero Member
  • *****
  • Posts: 16445
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Circle not closing properly when using negative radians
« Reply #6 on: January 29, 2013, 07:08:05 PM »
LOL, I got lost...  ;D
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

TerryRitchie

  • Hero Member
  • *****
  • Posts: 2264
  • FORMAT C:\ /Q /U /AUTOTEST (How to repair Win8)
    • Email
Re: Circle not closing properly when using negative radians
« Reply #7 on: January 29, 2013, 09:33:00 PM »
Here is a replacement CIRCLE subroutine I am working on, but I need some help please (see comments in the code).

Code: [Select]
SUB CIRCLES (cx!, cy!, r!, c~&, s!, e!, a!)

'**
'** What works:
'**
'** - supplying a start and end radian works.
'** - supplying negative start and end radians work.
'** - supplying 0 and 0 for start and end radians work.
'**
'** need help with the following:
'**
'** radian 0Pi is to the right, .5Pi the bottom, Pi to the left and 1.5Pi at the top.
'** this is upside down from QB and QB64 which should be:
'** radian 0Pi to the right, .5Pi at the TOP, Pi to the left and 1.5Pi at the BOTTOM.
'**
'** how do I get this to draw mirrored from the current way it's being performed?
'**
'** how do I incorporate aspect ratio into the formula below?
'**
'** the STEP value in the FOR/NEXT statement needs work. What's the best way to handle this?
'**

IF a! = 0 THEN a! = 1 '                                                      aspect ratio of 0 defaults to 1
IF s! < 0 THEN s% = -1: s! = -1 * s! '                                       line from center? if so remember and normalize s!
IF e! < 0 THEN e% = -1: e! = -1 * e! '                                       line from center? if so remember and normalize e!
x! = cx! + r! * COS(s!) '                                                    compute starting point on circle
y! = cy! + r! * SIN(s!)
IF s% THEN LINE (cx!, cy!)-(x!, y!), c~& ELSE PSET (x!, y!), c~& '           draw line to starting point or simply a point
IF e! <= s! THEN e! = e! + 6.2831852 '                                       come back around to proper location
FOR c! = s! TO e! STEP r! * .00001 '                                         cycle from start point to end point
    nx! = cx! + r! * COS(c!) '                                               compute next point on circle
    ny! = cy! + r! * SIN(c!)
    LINE -(nx!, ny!), c~& '                                                  connect the dots around circle
NEXT c!
IF e% THEN LINE -(cx!, cy!), c~& ELSE IF e! = 0 THEN LINE -(x!, y!), c~& '   draw line to center point or simply connect last dot

END SUB

codeguy

  • Hero Member
  • *****
  • Posts: 3552
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Circle not closing properly when using negative radians
« Reply #8 on: January 30, 2013, 10:30:20 AM »
i think you can always add 2pi to the starting and ending radians when using negative values and use one of my circle-drawing routines from unseenmachine's visual library modified to do a for/next or some such.
http://denteddisk.forums-free.com/make-an-appointment-with-the-resident-code-guru-f34.html

TerryRitchie

  • Hero Member
  • *****
  • Posts: 2264
  • FORMAT C:\ /Q /U /AUTOTEST (How to repair Win8)
    • Email
Re: Circle not closing properly when using negative radians
« Reply #9 on: February 02, 2013, 06:18:30 PM »
I now have a CIRCLE command replacement to use for now:

http://www.qb64.net/forum/index.php?topic=10593.0

  • Print