Complex maths

Started by matt, Sun 08/03/2009 09:27:41

Previous topic - Next topic

matt

Hi all. I am currently making a game and I need to figure out a point from a start xy, a distance and an angle. Would anyone know how to do this.
cheers
Matt

what?

Gilbert

Assuming that the angle is anticlockwise from positive x-axis and you are using the normal cartesean coordinates (if it's computer screen coordinates the y has to be negated), the formulae are:
x=startx+dist*cos(angle)
y=starty+dist*sin(angle)

paolo

#2
Quote from: Gilbet V7000a on Sun 08/03/2009 09:35:07
(if it's computer screen coordinates the y has to be negated)

If you're working in screen coordinates, the above formulae require the angle to be measured clockwise; if you are measuring the angle anticlockwise, then you need these instead:

x = startx + dist * cos(angle)
y = starty - dist * sin(angle)

Additionally, you might need to convert the angle from degrees to radians (I don't remember whether AGS trigonometric functions work in radians or degrees). Look up "cos" or "sin" in the AGS manual to see if this is necessary. If so, then I think it explains there how to do the conversion.

Dualnames

Probably might need an Abs function as well. I recall doing something similar and the scripting an Abs function came in really handy.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

DoorKnobHandle

Well, abs is really nothing more than:

Code: ags

float Math_Abs ( float value )
{
      if ( value < 0.0f )
            return -value;
      return value;
}


So it's very easy to work around which is probably the reason why it doesn't have much priority.

EDIT: Sorry, misunderstood your post there. :) (I could've sworn I was in the AGS next version feature suggestion thread).

Dualnames

No harm done. Show off!!! :D :D :D
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk