Author Topic: BANDIT Formula  (Read 10185 times)

Albert_redditt

  • Guest
BANDIT Formula
« on: August 09, 2012, 03:24:38 PM »
I'm still learning ASM and trying to convert Basic programs i wrote, to ASM.

Heres one of my hilariuos Trig Formulas.

Code: [Select]

setup all the progs vars to single or double precision , radius of 125 is for 640X480

radian = ATN(1) / 45
radius = 125

FOR deg1 = 0 TO 360

    c1 = COS(deg1 * radian)
    s1 = SIN(deg1 * radian)

    x1 = radius * c1
    y1 = radius * s1

    FOR deg2 = 0 TO 360 STEP 1

        c2 = COS(deg2 * radian)
        s2 = SIN(deg2 * radian)

        x2 = radius * c2 * c2 * COS(COS(deg2 * s1 * c2 * radian) * c1) * c2 * c2 / c1 * s1 * COS(deg2 * radian * c1)
        y2 = radius * s2 * s2 * SIN(COS(deg2 * c1 * s2 * radian) * s1) * s2 * s2 / s1 * s1 * SIN(deg2 * radian * s1)

        PSET (xctr + x1 + x2 , yctr + y1 + y2), 9

    NEXT

NEXT


dedndave

  • Member
  • *****
  • Posts: 8752
  • Still using Abacus 2.0
    • DednDave
Re: BANDIT Formula
« Reply #1 on: August 09, 2012, 07:40:51 PM »
try a Bresenham algo   :t
http://en.wikipedia.org/wiki/Midpoint_circle_algorithm

at any rate....
the FPU has intrinsic trig functions which should be reasonably fast

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: BANDIT Formula
« Reply #2 on: August 09, 2012, 10:16:09 PM »
It's not going to be easy. The attachment contains the compiled FreeBASIC app.
Well Microsoft, here’s another nice mess you’ve gotten us into.

qWord

  • Member
  • *****
  • Posts: 1471
  • The base type of a type is the type itself
    • SmplMath macros
Re: BANDIT Formula
« Reply #3 on: August 09, 2012, 11:40:58 PM »
looks interesting :biggrin:
Is this shape intended? Using my macros, the conversion is very easy - see attachment.
MREAL macros - when you need floating point arithmetic while assembling!

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: BANDIT Formula
« Reply #4 on: August 10, 2012, 01:32:32 AM »
qWord,

I had previously downloaded your SmplMath package, and forgot to look at it. Now that I have I’m impressed, good job  :t

The shape that your code produces does look somewhat like a cartoon version of a Mexican bandit:

http://fc02.deviantart.net/fs6/i/2005/030/f/4/Mexican_bandit_mascot_by_pas_designs.jpg

Well Microsoft, here’s another nice mess you’ve gotten us into.

jj2007

  • Member
  • *****
  • Posts: 7763
  • Assembler is fun ;-)
    • MasmBasic
Re: BANDIT Formula
« Reply #5 on: August 10, 2012, 02:23:20 AM »
qWord,

I had previously downloaded your SmplMath package, and forgot to look at it. Now that I have I’m impressed, good job  :t

I can echo that :t

qWord

  • Member
  • *****
  • Posts: 1471
  • The base type of a type is the type itself
    • SmplMath macros
Re: BANDIT Formula
« Reply #6 on: August 10, 2012, 04:00:00 AM »
I had previously downloaded your SmplMath package, and forgot to look at it. Now that I have I’m impressed, good job  :t
thx  :biggrin:

The shape that your code produces does look somewhat like a cartoon version of a Mexican bandit:
that explains the name  :lol:
MREAL macros - when you need floating point arithmetic while assembling!

Albert_redditt

  • Guest
Re: BANDIT Formula
« Reply #7 on: August 10, 2012, 06:16:40 AM »
@QWord 
Your formula is not the correct height, its flat on the vertical.

        ldl deg1 = 180 , radian = 0.01745329252 ; = Pi/180°

        .while deg1 <= 360


ldl deg1=180 should be ldl deg1=0

               
                ldl radius = 50  ; should be ~y_resolution / (somewhere betwen 5 to 7)
               
                invoke BANDIT,ps.hdc,radius,150,150  ;  the (150,150)  should be  x_resolution / 2  ,  y_resolution/2
   

dedndave

  • Member
  • *****
  • Posts: 8752
  • Still using Abacus 2.0
    • DednDave
Re: BANDIT Formula
« Reply #8 on: August 10, 2012, 03:34:25 PM »
i thought it was 1 radian = 180 degrees/pi ~ 57.3 degrees

FORTRANS

  • Member
  • ****
  • Posts: 946
Re: BANDIT Formula
« Reply #9 on: August 10, 2012, 10:35:22 PM »
Hi Dave,

  Yes, a radian is an arc length on the circle equal to
the radius of the circle.  There are two pi radians in the
circumference of a circle.  So, about 57.3 degrees.

Cheers,

Steve N.

dedndave

  • Member
  • *****
  • Posts: 8752
  • Still using Abacus 2.0
    • DednDave
Re: BANDIT Formula
« Reply #10 on: August 10, 2012, 11:46:17 PM »

Albert_redditt

  • Guest
Re: BANDIT Formula
« Reply #11 on: August 11, 2012, 09:16:14 AM »
In my trig formulas instead of looping -PI to PI   or  0 to PI*2
 
  I loop 0 to 360 degrees and multiply the degree by 1 degree worth or radians (.01745).
  1 degree worth of radians is the ArcTangent of 1 (45 degrees) divided by 45.

  I usually just call the "ATN(1)/45" a "rad" or "radian" or "r1 or r2" . but its not actually a radian, its 1 degree of radians.
  and then do a
     cosine = cos(deg1*rad) instead of a cosine = cos(theta)
     
Most everybody else uses radians or what they call theta.
  loop 0 to PI*2 step theta  (.01745)
     c = cos(theta)
     s = sin(theta)

I just use degrees , because i'm an untrained mathematician and probably a moron as well.

dedndave

  • Member
  • *****
  • Posts: 8752
  • Still using Abacus 2.0
    • DednDave
Re: BANDIT Formula
« Reply #12 on: August 11, 2012, 10:33:56 AM »
that is the fundamental flaw in your method

rather than stepping by degrees or radians....
step by pixels

for all the "orthogonals", it does not matter whether you step by X or by Y
the orthogonals are 0, 45, 90, 135, 180, 225, 270, 315, and 360

but - in between these angles, step by X if the slope of the tangent is between -1 and 1
otherwise, step by Y

you will be much happier with your circle   :t

dedndave

  • Member
  • *****
  • Posts: 8752
  • Still using Abacus 2.0
    • DednDave
Re: BANDIT Formula
« Reply #13 on: August 11, 2012, 10:54:14 AM »
to expand on that a little.....

make 2 loops - one that steps by X, one that steps by Y

for 315 to 45 degrees, step by X
for 45 to 135 degrees, step by Y
for 135 to 225 degrees, step by X
for 225 to 315 degrees, step by Y

FORTRANS

  • Member
  • ****
  • Posts: 946
Re: BANDIT Formula
« Reply #14 on: August 11, 2012, 10:37:10 PM »
Hi,

   To elaborate on Dave's comment; you should not step
by a degree because with a large circle you will be plotting
dots rather than a continuous circle.  And with a small circle,
you will be plotting the pixels on the circle multiple times.

   If you increment by pixels you end up with a continuous
line/circle.  And you don't overplot pixels.  This is one of
the ideas behind Bresenham's circle algorithm.

HTH,

Steve N.