home *** CD-ROM | disk | FTP | other *** search
- ===========================================================================
- BBS: PC Connect
- Date: 07-16-92 (00:10) Number: 13498
- From: PETER FICHERA Refer#: NONE
- To: ROBERT HELMBOLD Recvd: NO
- Subj: CIRCLE Conf: (11) R-QBasic
- ---------------------------------------------------------------------------
- ' RH>JP>RH>JP>EL> Does anybody know how to determine the largest squ
- ' RH>JP> >JP>EL>box inside
- ' ^^^^^^
-
- ' RH>JP> >JP>EL>a circle created with QB's CIRCLE with a known radius? So
- ' RH>JP> >JP>the coordinates of the box are (x-r,y), (x,y+r), (x+r,y) and
- ' RH>JP> >JP>(x,y-r). Draw lines connecting the four corners.
- ' RH>JP> >~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ' ^^^^^
- ' This gives a DIAMOND.
-
- ' RH>JP> >Careful. That will give the *smallest* square *outside* the circ
- ' RH>JP>
- ' RH>JP>Not true.
- ' RH>JP>Try it.
- ' RH>~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ' RH>You are correct. I was too hasty there.
-
- ' Wha' yo talkin' 'bout? Robert is correct: I hereby submit a small
- ' program, originally in AmigaBASIC but ported to the IBM--on a CGA Lo-Res
- ' screen, no less--that demonstrates just the problem--and the solution.
-
- ' You see, in most forms of Microsoft BASIC, CIRCLE compensates for the
- ' inconvenience of odd shaped pixels with a default aspect ratio: On the
- ' Mac, and in VGA modes with square pixels, it's 1; on a high-res CGA
- ' screen, it's .44. So, you have to compensate for this somehow, and the
- ' compensations are imperfect--hence the fudge-factors in the following
- ' code:
-
- ' ----------------------------- CUT HERE -------------------------------
- Machine$ = "IBM"
-
- ' Does anybody know how to determine the largest squrare box inside
- ' a circle created with QB's CIRCLE with a known radius?
-
-
- 'the coordinates of the box are (x-r,y), (x,y+r), (x+r,y) and
- '(x,y-r). Draw lines connecting the four corners.
-
-
- IF Machine$ = "IBM" THEN
- SCREEN 1
- END IF
-
- 'for the greatest Circumscribed DIAMOND, instead of
-
- sq2=SQR(2)/2
-
- ' use
- ' sq2 = SQR(2)
-
-
-
- x = 160 ' Center the circle on screen
- y = 100
- r = 50 ' Circle is 50 pixels in nominal radius
- ar = 1 ' Actual Aspect Ratio to be shown
- sar = .88 ' Screen Aspect ratio
- nar = ar * sar ' Net Aspect Ratio
- rr = r * nar - 1 ' y value of radius. ("-1") is fudge-factor!
- ' NOTE: For general use, you'll have to be a LOT
- ' cleverer than this if you want to use ellipses...
-
- CIRCLE (x, y), r, 1 ' make the call
-
- ' Corners of outside box:
- xb = x - r
- xf = x + r
- yb = y - rr
- yf = y + rr
-
- 'Box OUTSIDE the CIRCLE
- LINE (xb, yb)-(xf, yf), 2, B
-
- irx = INT(r * sq2) - 1' 1/2 the width of inside box
- ' with fudge-factor
- iry = irx * nar ' 1/2 the hight of box--acct'ing for AR.
-
- ' Corners of inside box
- xbi = x - irx
- xfi = x + irx
- ybi = y - iry
- yfi = y + iry
-
- 'Call it!
- LINE (xbi, ybi)-(xfi, yfi), 3, B
-
-
- '------------------------------CUT HERE-------------------------
-
- ' Of course, if you want a DIAMOND, then use
-
- LINE (x,yb)-(xb,y)
- LINE (xb,y)-(x,yf)
- LINE (x,yf)-(xf,y)
- LINE (xf,y)-(x,yb)
-
-
- ' [:^)>
-
- PCRelay:LOCKSOFT -> #981 RelayNet (tm)
- 4.11 Locksoft bbs (714)766-8219 Hemet CA/HST 24hrs
-