The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

need some trig help for continuous rock-paper-scissors

Hi, I am making a turn-based strategy game and as part of it I need a function that to determine how different units matchup against each other.  I want to to look like the sin function, but the maximum will be at 120 rather than 90, and the minimum will be at 240 rather than 270.  Zeroes will still be at 0, 180, and 360.  I was thinking that something like:

sin(f(x)) would work, but I don't know what f would be.  Thanks for any assistance.
Tom C
Sunday, September 30, 2007
You can use any function which maps:

0 -> 0
90 -> 120
180 -> 180
270 -> 240
360 -> 360

An example of such a function is:

f(x) =
if (0<x<90) -> x*4/3
if (90<x<180) -> 90+((x-90)*2/3)
Christopher Wells Send private email
Sunday, September 30, 2007
Add some phase modulation using the same frequency, like that:

y = sin((x-34*sin(x*M_PI/180))*M_PI/180)

Here 34 degrees is maximum phase deviation.  Adjust it so that the maximums of y are in exactly the right places.
Jeff Zanooda Send private email
Sunday, September 30, 2007
Thank you very much
Tom C
Sunday, September 30, 2007

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz