News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

BANDIT Formula

Started by Albert_redditt, August 09, 2012, 03:24:38 PM

Previous topic - Next topic

Albert_redditt

I'm still learning ASM and trying to convert Basic programs i wrote, to ASM.

Heres one of my hilariuos Trig Formulas.



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

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

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

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

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

Quote from: MichaelW 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

I can echo that :t

qWord

Quote from: MichaelW on August 10, 2012, 01:32:32 AMI had previously downloaded your SmplMath package, and forgot to look at it. Now that I have I'm impressed, good job  :t
thx  :biggrin:

Quote from: MichaelW on August 10, 2012, 01:32:32 AM
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

@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

i thought it was 1 radian = 180 degrees/pi ~ 57.3 degrees

FORTRANS

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


Albert_redditt

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

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

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

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.