[COMPLETED 075A] Sin, cos, tan

Post your Feature Requests here...
Post Reply
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

[COMPLETED 075A] Sin, cos, tan

Post by Juutis » Wed Apr 26, 2006 3:04 pm

It would be really useful to be able to use the trigonometrical functions (or whatever they are called) sin, cos, and tan in scripting. At least I didn't find any way to use them, so I guess they're not there.
Pain is only psychological.

User avatar
AndyCR
Posts: 1449
Joined: Wed Jul 06, 2005 5:08 pm
Location: Colorado, USA
Contact:

Post by AndyCR » Wed Apr 26, 2006 3:21 pm

that's a very good point.

(bookmarks this page for RF2)

User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico » Thu Apr 27, 2006 1:22 pm

In the new RFwithPhysics release will be a Math command (added by Nout toghether with all the new features) that will allow all the
math functions. You will have to wait some week.

Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay » Sun Jan 28, 2007 4:51 pm

It would also be good to have the reverse functions asin(), acos() and atan() which return radians from a given number.
Everyone can see the difficult, but only the wise can see the simple.
-----

User avatar
federico
RF Dev Team
Posts: 443
Joined: Tue Jul 05, 2005 3:14 pm
Contact:

Post by federico » Sun Jan 28, 2007 6:12 pm

RFwithPhysics never officially came out so these kin of commands weren't implemented in the current source.
If QoD wants to add them here's the command (you will probably have to change some variable's name):

Code: Select all

	case 119: //value = Math(Function, Value1);
			  //value = Math(Function, Value1,Value2);
		{
			strcpy(string1, arguments[0].str());
			if (!stricmp(string1,"abs"))
			{
				PARMCHECK(2);
				returnValue = (int)(abs(arguments[1].intValue()));
			}
			else if (!stricmp(string1,"fabs"))
			{
				PARMCHECK(2);
				returnValue = (float)(fabs(arguments[1].floatValue()));
			}
			else if (!stricmp(string1,"ceil"))
			{
				PARMCHECK(2);
				returnValue = (int)(ceil(arguments[1].floatValue()));
			}
			else if (!stricmp(string1,"floor"))
			{
				PARMCHECK(2);
				returnValue = (int)(floor(arguments[1].floatValue()));
			}
			else if (!stricmp(string1,"mod"))
			{
				PARMCHECK(3);
				returnValue = (float)(fmod(arguments[1].floatValue(), arguments[2].floatValue()));
			}
			else if (!stricmp(string1,"sqrt"))
			{
				PARMCHECK(2);
				returnValue = (float)(sqrt(arguments[1].floatValue()));
			}
			else if (!stricmp(string1,"min"))
			{
				int val1 = arguments[1].intValue();
				if(arguments.entries()>2)
				{
					for(int i=2; i < int(arguments.entries()); i++)
					{
						int val2 = arguments[i].intValue();
						if (val1 > val2)
							val1 = val2;
					}
				}
				returnValue = (int)val1;
			}
			else if (!stricmp(string1,"max"))
			{
				int val1 = arguments[1].intValue();
				if(arguments.entries()>2)
				{
					for(int i=2; i < int(arguments.entries()); i++)
					{
						int val2 = arguments[i].intValue();
						if (val1 < val2)
							val1 = val2;
					}
				}
				returnValue = (int)val1;
			}
			else if (!stricmp(string1,"fmin"))
			{
				float val1 = arguments[1].floatValue();
				if(arguments.entries()>2)
				{
					for(int i=2; i < int(arguments.entries()); i++)
					{
						float val2 = arguments[i].floatValue();
						if (val1 > val2)
							val1 = val2;
					}
				}
				returnValue = (float)val1;
			}
			else if (!stricmp(string1,"fmax"))
			{
				float val1 = arguments[1].floatValue();
				if(arguments.entries()>2)
				{
					for(int i=2; i < int(arguments.entries()); i++)
					{
						float val2 = arguments[i].floatValue();
						if (val1 < val2)
							val1 = val2;
					}
				}
				returnValue = (float)val1;
			}
			else if (!stricmp(string1,"pow"))
			{
				PARMCHECK(3);
				returnValue = (float)(pow(arguments[1].floatValue(), arguments[2].floatValue()));
			}
			else if (!stricmp(string1,"cos"))
			{
				PARMCHECK(2);
				returnValue = (float)(cos(arguments[1].floatValue()));
			}
			else if (!stricmp(string1,"sin"))
			{
				PARMCHECK(2);
				returnValue = (float)(sin(arguments[1].floatValue()));
			}
			else if (!stricmp(string1,"tan"))
			{
				PARMCHECK(2);
				returnValue = (float)(tan(arguments[1].floatValue()));
			}
			else if (!stricmp(string1,"acos"))
			{
				PARMCHECK(2);
				returnValue = (float)(acos(arguments[1].floatValue()));
			}
			else if (!stricmp(string1,"asin"))
			{
				PARMCHECK(2);
				returnValue = (float)(sin(arguments[1].floatValue()));
			}
			else if (!stricmp(string1,"atan"))
			{
				PARMCHECK(2);
				returnValue = (float)(tan(arguments[1].floatValue()));
			}
			else if (!stricmp(string1,"atoi"))
			{
				PARMCHECK(2);
				returnValue = (int)(atoi(arguments[1].str()));
			}
			else if (!stricmp(string1,"atof"))
			{
				PARMCHECK(2);
				returnValue = (float)(atof(arguments[1].str()));
			}
			else
			{
				char szBug[128];
				sprintf(szBug,"Math function %s does not exist!",string1);
				CCD->Engine()->ReportError(szBug, true);
				exit(0);
			}
			return true;
		}
The code is by Nout naturally.

Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay » Tue Jan 30, 2007 9:07 pm

ah that's good thanks!
Everyone can see the difficult, but only the wise can see the simple.
-----

Jay
RF Dev Team
Posts: 1232
Joined: Fri Jul 08, 2005 1:56 pm
Location: Germany

Post by Jay » Mon Feb 12, 2007 7:02 pm

got it implemented into my version of the source. I will make it available soon so that everyone can use it.
Everyone can see the difficult, but only the wise can see the simple.
-----

Post Reply