Page 1 of 1
[COMPLETED 075A] Sin, cos, tan
Posted: Wed Apr 26, 2006 3:04 pm
by Juutis
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.
Posted: Wed Apr 26, 2006 3:21 pm
by AndyCR
that's a very good point.
(bookmarks this page for RF2)
Posted: Thu Apr 27, 2006 1:22 pm
by federico
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.
Posted: Sun Jan 28, 2007 4:51 pm
by Jay
It would also be good to have the reverse functions asin(), acos() and atan() which return radians from a given number.
Posted: Sun Jan 28, 2007 6:12 pm
by federico
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.
Posted: Tue Jan 30, 2007 9:07 pm
by Jay
ah that's good thanks!
Posted: Mon Feb 12, 2007 7:02 pm
by Jay
got it implemented into my version of the source. I will make it available soon so that everyone can use it.