Trig and Maptools

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

wandering_sage
Kobold
Posts: 9
Joined: Fri Sep 12, 2008 6:31 pm

Trig and Maptools

Post by wandering_sage »

Hello :D

I'm a novice programmer who is using Map tools in an attempt to host a turn based space simulator for some friends and my own intellectual loafing.

The gist of the post is are there any trig functions available in map tools?

When your in your space ship and you rotate say 15 degrees and then gun your main engines (the ones on the back of the ship) Your new position (X,Y) can be determined using trig x + = math.cos(angle of rotation) * speed and y + = math.sine(angle of rotation) * speed

That's how you do it in VB are there any equivalent functions available in Map tools that i could use to achieve a similar effect

I hope to build a few macro's that automates movement taking relative velocity and rotation into account to help you maneuver your ship

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: Trig and Maptools

Post by jfrazierjr »

Here is the documentation of the list of built in "math" functions available in the RPtools projects: http://lmwcs.com/rptools/wiki/Category: ... l_Function

I believe someone posted that you can do a "long" form set of formula's using standard operations to get at sine/cosine stuff, but you have to know the formula(which I don't).
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

wandering_sage
Kobold
Posts: 9
Joined: Fri Sep 12, 2008 6:31 pm

Re: Trig and Maptools

Post by wandering_sage »

Had that site bookmarked already didn't see anything about trig functions. Maybe I should add this to the wall of features

User avatar
RPTroll
TheBard
Posts: 3159
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Re: Trig and Maptools

Post by RPTroll »

wandering_sage wrote:Had that site bookmarked already didn't see anything about trig functions. Maybe I should add this to the wall of features
Right in there with the 'mod' function.
ImageImage ImageImageImageImage
Support RPTools by shopping
Image
Image

User avatar
zEal
Dragon
Posts: 944
Joined: Sun Mar 22, 2009 2:25 am

Re: Trig and Maptools

Post by zEal »

onCampaignLoad

Code: Select all

[ defineFunction( "radians", "radians@this", 1, 1 ) ]
[ defineFunction( "degrees", "degrees@this", 1, 1 ) ]
[ defineFunction( "sine", "sine@this", 1, 1 ) ]
[ defineFunction( "cosine", "cosine@this", 1, 1 ) ]
[ defineFunction( "factorial", "factorial@this", 1, 1 ) ]
[ defineFunction( "pi", "pi@this", 1, 1 ) ]
[ defineFunction( "modulo", "modulo@this", 1, 1 ) ] 
radians

Code: Select all

[ Degrees = arg( 0 ) ]
[ macro.return = Degrees * ( pi() / 180 ) ] 
degrees

Code: Select all

[ Radians = arg( 0 ) ]
[ macro.return = Radians * ( 180 / pi() ) ] 
sine

Code: Select all

[ Radians = arg( 0 ) ]
[ Sine = Radians - ( power( Radians, 3 ) / factorial( 3 ) ) +
    ( power( Radians, 5 ) / factorial( 5 ) ) -
    ( power( Radians, 7 ) / factorial( 7 ) ) +
    ( power( Radians, 9 ) / factorial( 9 ) ) -
    ( power( Radians, 11 ) / factorial( 11 ) ) +
    ( power( Radians, 13 ) / factorial( 13 ) ) -
    ( power( Radians, 15 ) / factorial( 15 ) )
]
[ macro.return = Sine ] 
cosine

Code: Select all

[ Radians = arg( 0 ) ]
[ Cosine = 1 - ( power( Radians, 2 ) / factorial( 2 ) ) +
    ( power( Radians, 4 ) / factorial( 4 ) ) -
    ( power( Radians, 6 ) / factorial( 6 ) ) +
    ( power( Radians, 8 ) / factorial( 8 ) ) -
    ( power( Radians, 10 ) / factorial( 10 ) ) +
    ( power( Radians, 12 ) / factorial( 12 ) ) -
    ( power( Radians, 14 ) / factorial( 14 ) )
]
[ macro.return = Cosine ] 
factorial

Code: Select all

[ Number = arg( 0 ) ]
[ if( Number <= 1 ), code:
{
    [ macro.return = 1 ]
};{
    [ macro.return = Number * factorial( Number-1 ) ]
} ] 
pi

Code: Select all

[ macro.return = 3.14159265358979323846 ] 
modulo

Code: Select all

[ Number = arg( 0 ) ]
[ Divider = arg( 1 ) ]
[ macro.return = Number - ( Divider * floor( Number / Divider ) ) ] 
The sine and cosine are accurate to around 16 decimal places.

User avatar
RPTroll
TheBard
Posts: 3159
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Re: Trig and Maptools

Post by RPTroll »

zEal wrote:The sine and cosine are accurate to around 16 decimal places.
pffft. Like that's even close to the accuracy I'll need.

heh. Great stuff. Thanks!
ImageImage ImageImageImageImage
Support RPTools by shopping
Image
Image

User avatar
zEal
Dragon
Posts: 944
Joined: Sun Mar 22, 2009 2:25 am

Re: Trig and Maptools

Post by zEal »

RPTroll wrote:pffft. Like that's even close to the accuracy I'll need.
You'd think so, but when performing a series of trig operations, the lack of precision starts to add up and the answer might just end up wrong. :)

Now if someone that has better understanding of 'natural mathematics', would chime in with how to figure out tangent, arc sine, arc cosine, and arc tangent, we would be all set. ;)

zylosan
Giant
Posts: 102
Joined: Sun Jun 28, 2009 11:08 pm

Re: Trig and Maptools

Post by zylosan »

A related question to this topic.

Is it even possible to represnt a three axis grip on map tools. (X,Y,Z)

wandering_sage
Kobold
Posts: 9
Joined: Fri Sep 12, 2008 6:31 pm

Re: Trig and Maptools

Post by wandering_sage »

Are you talking about representing a tokens elevation on the map? If So just make some custom States with a lil diagonal line who's length is proportionate to there elevation

User avatar
RPTroll
TheBard
Posts: 3159
Joined: Tue Mar 21, 2006 7:26 pm
Location: Austin, Tx
Contact:

Re: Trig and Maptools

Post by RPTroll »

You could also use a vertical health bar to represent altitude.
ImageImage ImageImageImageImage
Support RPTools by shopping
Image
Image

Akodo Makama
Giant
Posts: 249
Joined: Mon Apr 20, 2009 9:31 pm

Re: Trig and Maptools

Post by Akodo Makama »

zEal wrote:
RPTroll wrote:pffft. Like that's even close to the accuracy I'll need.
You'd think so, but when performing a series of trig operations, the lack of precision starts to add up and the answer might just end up wrong. :)

Now if someone that has better understanding of 'natural mathematics', would chime in with how to figure out tangent, arc sine, arc cosine, and arc tangent, we would be all set. ;)
Tan(x)= sin(x)/cos(x)
arcsin(x) = x + 1/2 (x^3/3) + (1/2)(3/4)(x^5/5) + (1/2)(3/4)(5/6)(x^7/7) +...
arctan(x) = x - x^3/3 + x^5/5 - x^7/7 + x^9/9 - x^11/11 +...
arccos(x) = pi()/2 -x -x^3/6 -3x^5/40 - 5x^7/112 - 35x^9/1152 - 63x^11/2816 -...

User avatar
zEal
Dragon
Posts: 944
Joined: Sun Mar 22, 2009 2:25 am

Re: Trig and Maptools

Post by zEal »

Akodo Makama wrote:Tan(x)= sin(x)/cos(x)
arcsin(x) = x + 1/2 (x^3/3) + (1/2)(3/4)(x^5/5) + (1/2)(3/4)(5/6)(x^7/7) +...
arctan(x) = x - x^3/3 + x^5/5 - x^7/7 + x^9/9 - x^11/11 +...
arccos(x) = pi()/2 -x -x^3/6 -3x^5/40 - 5x^7/112 - 35x^9/1152 - 63x^11/2816 -...
Good stuff :)

Could you explain how to add precision to arc cosine? Those numbers seem completely arbitrary to me as I can't seem to grok a pattern.

Akodo Makama
Giant
Posts: 249
Joined: Mon Apr 20, 2009 9:31 pm

Re: Trig and Maptools

Post by Akodo Makama »

zEal wrote:
Akodo Makama wrote:Tan(x)= sin(x)/cos(x)
arcsin(x) = x + 1/2 (x^3/3) + (1/2)(3/4)(x^5/5) + (1/2)(3/4)(5/6)(x^7/7) +...
arctan(x) = x - x^3/3 + x^5/5 - x^7/7 + x^9/9 - x^11/11 +...
arccos(x) = pi()/2 -x -x^3/6 -3x^5/40 - 5x^7/112 - 35x^9/1152 - 63x^11/2816 -...
Good stuff :)

Could you explain how to add precision to arc cosine? Those numbers seem completely arbitrary to me as I can't seem to grok a pattern.
I just copypasted what MatLab spit out at me.

User avatar
Brigand
Read-only User
Posts: 1623
Joined: Thu Feb 14, 2008 8:57 am
Location: Nosy GM's can go frak themselves!

Re: Trig and Maptools

Post by Brigand »

arcsin(x) = x + 1/2 (x^3/3) + (1/2)(3/4)(x^5/5) + (1/2)(3/4)(5/6)(x^7/7)

The pattern looks pretty simple to me: x + a/b (x^c/c)

Add two to c and then fill in the rest backwards, subtracting one for each a/b pair required to however precise you need it to be.

User avatar
zEal
Dragon
Posts: 944
Joined: Sun Mar 22, 2009 2:25 am

Re: Trig and Maptools

Post by zEal »

Akodo Makama wrote:I just copypasted what MatLab spit out at me.
Is there any way of having it spit out more? :)








Here's a corrected/improved modulo. The original didn't properly handle non-absolute values or floating point numbers. When performing modulo on floating point numbers, you could end up with a number with a lot of decimal places. Use Trim Number if need be.

Code: Select all

[ Number = arg( 0 ) ]
[ Divider = arg( 1 ) ]
[ Modulo = Divider * ( ( abs( Number ) / Divider ) - floor( abs( Number ) / Divider) ) ]
[ macro.return = if( abs( Number ) == Number, Modulo, -Modulo ) ] 

Post Reply

Return to “Macros”