Path: chuka.playstation.co.uk!news From: "Rad" Newsgroups: scee.yaroze.programming.2d_graphics Subject: Re: What do'you mean I have to brush up on me maths! Date: Sun, 11 Jul 1999 17:36:02 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 67 Message-ID: <7mah71$t1v6@chuka.playstation.co.uk> References: <7ko1jf$33u25@chuka.playstation.co.uk> <376fbd21.251404588@news.scea.sony.com> <7lkucs$ko217@chuka.playstation.co.uk> <7lnteg$i9a1@chuka.playstation.co.uk> <37823145.682258342@news.scea.sony.com> NNTP-Posting-Host: modem-195.name53.dialup.pol.co.uk X-Newsreader: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Thanks for the help guys. Right, next question :) I want to move something in a continuous sound wave frequency type pattern, does anybody know if I can do that with a maths formula? Thanks, Rad. rad@cyberdude.com http://www.netyaroze-europe.com/~radpsx p.s. Scott - did you find out which method (sqrt or inv_tan) was faster? Oh and why can't you just use a simple look-up table for inv_tan? Scott Cartier wrote in message <37823145.682258342@news.scea.sony.com>... >>Hi Rad, >> >>First find the distance between the two objects: >> >> dx = x1 - x2 >> dy = y1 - y2 >> >>Next find the length of the line between the two objects: >> >> dxy = square_root( dx*dx + dy*dy ) >> >>And now the vector: >> >> vx = (dx * speed) / dxy >> vy = (dy * speed) / dxy >> >> >>I think that'll do the trick. Due to the integer maths, there will be >>accuracy problems if the speed is low, or if the two objects are very close, >>but this can be fixed by using fixed point if necessary. >> >>Herbs > > >You can avoid the squareroot by doing an inverse tangent instead. >Whether this is faster or not I'm not sure. First, find dx & dy like >above. Then find the angle of this line: > > Angle = inverse_tan(dy / dx) > >Once you have the angle you can get the vx & vy components using sin >and cos: > > vx = cos(angle) > vy = sin(angle) > >I hope I didn't get those switched. > >Use a look-up table for the tan, sin, and cos to speed things up. The >inverse tangent takes a bit longer despite using a look-up table. >This may or may not actually be faster than doing the sqrt() as Alex >suggests. That would be an interesting experiment (and one I probably >should have performed before blindly going with the inverse tan >method). > >Scott