I just want to be able to calculate the position of points around the
perimeter of a circle...
Good Luck
Alexei A. Frounze
-----------------------------------------
Homepage: http://alexfru.chat.ru
Mirror: http://members.xoom.com/alexfru
> Can anybody point me out a method to calculate sin/cos in
> assembler?
Do you mean, using integer-only assembler? I'd suggest you get one of the
old maths libraries for 386s and the non-FPU like. If you get the source
code, great. If you don't, disassemble it.
You realise that current generation chips all have floating point units,
and certainly the x86 has floating-point sine and cosine in a single
instruction?
I guess I could just use another language to calculate
> them and write 'em to a file, then read from the file, but I don't
> even know where to begin on reading from a file...
This might be your best bet. Calculating sin/cos is difficult. Look for
'MacLarin expansion' (can't remember the damn spelling).
You can do the file operations in a C program, then incorporate assembler
in the middle of it.
Richard.
If you need trig. functions only for circle plotting, do a search for
Brensham's Algorithm. These algorithms provide methods for plotting straight
lines, circles, ellipses etc. without using _any_ floating-point arithmetic.
Any decent text about graphics algoritmhs should contain them.
Daniel Pfeffer
The classic method for this type of things is using Taylor's polynom
replacement for the desired function. The base formula is:
f(x) = f(x0) + f'(x0)*(x-x0) + f''(x0)*(x-x0)^2/2! + f'''(x0)*(x-x0)
^3/3! + ...
where 'x' is the value which function you're calculating and x0 is some
point which value you know well (e.g. 0 or PI/2 for trig functions).
Obviously you cannot sum until infinity, so if you stop calculating on
some N, the maximum error will be f<N+1>' (x0)*(x - x0)^(N+1)/(N+1)!.
The more times you do the calculation & addition, the more precise
result you get. E.g. if you take for simplicity x0 = 0 you get:
sin(x) = x - x^3/3! + x^5/5! - x^7/7! + ...
cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! + ...
tg(x) = sin(x)/cos(x)
ctg(x) = cos(x)/sin(x)
That's the way any FPU or calculator will do the trig. Note that
it's very hard and long to do the calculation only with integer
instructions in assembler. If you can use FPU that has FSIN/FCOS
instructions then it will do all the trick for you.
> I guess I could just use another language to calculate them and write
'em to a
> file, then read from the file, but I don't even know where to begin on
> reading from a file... I've had no luck finding information on the
net
> baout calculating sin/cos...
>
> I just want to be able to calculate the position of points around
the
> perimeter of a circle...
If you mind speed you may want to do exactly this: calculate all
posible values to, say, 1/10 degree and store them to a file. At the
beginning of the program load them to the reference table in RAM and
approximate the needed value to the best match entry in the table.
-- http://bphantom.hypermart.net --
-- Too many flames with too much to burn
And life's only made of paper --
Sent via Deja.com http://www.deja.com/
Before you buy.
When n gp to infini....the value go to null
Daniel M. Pfeffer <pfef...@nospam.internet-zahav.net> a écrit dans le
message : 8g0nce$720$1...@bob.news.rcn.net...
> "Brian Clow" <bc...@home.com> wrote in message
> news:si6n4cg...@corp.supernews.com...
> >
> > Can anybody point me out a method to calculate sin/cos in assembler?
> I
> > guess I could just use another language to calculate them and write 'em
to
> a
> > file, then read from the file, but I don't even know where to begin on
> > reading from a file... I've had no luck finding information on the net
> > baout calculating sin/cos...
> >
> > I just want to be able to calculate the position of points around
the
> > perimeter of a circle...
>
>If you need trig. functions only for circle plotting, do a search for
>Brensham's Algorithm. These algorithms provide methods for plotting straight
>lines, circles, ellipses etc. without using _any_ floating-point arithmetic.
>Any decent text about graphics algoritmhs should contain them.
IMHO, you'll get better results by searching for Bresenham's Algorithm.
--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL: http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper 4-line sig. separator is as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)