The MASM Forum
General => The Laboratory => Topic started by: Albert_redditt 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.
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
-
try a Bresenham algo :t
http://en.wikipedia.org/wiki/Midpoint_circle_algorithm (http://en.wikipedia.org/wiki/Midpoint_circle_algorithm)
at any rate....
the FPU has intrinsic trig functions which should be reasonably fast
-
It's not going to be easy. The attachment contains the compiled FreeBASIC app.
-
looks interesting :biggrin:
Is this shape intended? Using my macros, the conversion is very easy - see attachment.
-
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 (http://fc02.deviantart.net/fs6/i/2005/030/f/4/Mexican_bandit_mascot_by_pas_designs.jpg)
(http://fc02.deviantart.net/fs6/i/2005/030/f/4/Mexican_bandit_mascot_by_pas_designs.jpg)
-
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
-
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:
-
@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
-
i thought it was 1 radian = 180 degrees/pi ~ 57.3 degrees
-
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.
-
(http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/18.gif)
-
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.
-
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
-
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
-
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.
-
yes - it will make a circle that can be filled :P
the main advantage of using Bresenham is that integer calculations are performed between steps
the circle algo was derived from the Bresenham Line algo
i have adapted the same idea to other things with good results
-
i happened to catch this photo on MSN
it is supposed to be a perseid meteor
but, it looks to me like Bresenham may have had a hand in it :lol:
(http://col.stb01.s-msn.com/i/E7/BF959D817C59911A59A248982D3CF.jpg)