# RPTools.net

Discussion and Support

It is currently Tue Feb 20, 2018 3:01 am

 Page 2 of 2 [ 22 posts ] Go to page Previous  1, 2
Author Message
 aliasmask   Deity Joined: Tue Nov 10, 2009 6:11 pmPosts: 8009Location: Bay Area
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]Posted: Sun Aug 19, 2012 11:35 am
Remind me tomorrow to look at this. Converting degrees and radians can be tricky when doing the formulas.

_________________

 wolph42   Deity Joined: Fri Mar 20, 2009 4:40 amPosts: 9481Location: Netherlands
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]Posted: Sun Aug 19, 2012 12:30 pm
I remember banging my head in the wall while working with MT angles. I know I've created some utile to help with this, they might be on my bag of tricks. It not ill need to look around.

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

 Bone White   Great Wyrm Joined: Tue Aug 23, 2011 10:41 amPosts: 1134Location: Cornwall, UK
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]Posted: Sun Aug 19, 2012 12:39 pm
I know that 0 facing angle is actually pointing east in MapTool, and Y counts positive in a south direction, hence [r: yDiff = 0 - (targetY - initiativeY)]. I may look into how to calculate the trig functions myself to see if I can figure out why.

_________________
How to get around the two code nest limit in MapTool (and MOTE)

 Bone White   Great Wyrm Joined: Tue Aug 23, 2011 10:41 amPosts: 1134Location: Cornwall, UK
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]Posted: Sun Aug 19, 2012 1:08 pm
Using http://en.wikipedia.org/wiki/Inverse_tr ... arctangent and checking my calculations through google's calculator, my code below gives a much better accuracy with arcTan, to within five decimal places of accuracy (in degrees using Math:lib's toDegrees() function when testing a perfect 45 degree angle, it produces 44.999996367593779960265468547835435976910

This leads me to believe that your arcTan function was erroneous. Please dissect my workings and prove me wrong.

arcTan()
Code:
[h: z = arg(0)]
[
h: a = 999]
[
h, for (i,10,0,-1), code :
{
[h: j = 2 * i - 1]
[h: a = j + (* z)*(* z) / a]
}
]
[
h: macro.return = z / a]

_________________
How to get around the two code nest limit in MapTool (and MOTE)

Last edited by Bone White on Sun Aug 19, 2012 5:23 pm, edited 1 time in total.

 Bone White   Great Wyrm Joined: Tue Aug 23, 2011 10:41 amPosts: 1134Location: Cornwall, UK
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]Posted: Sun Aug 19, 2012 5:22 pm
... and the results of my labours, a UDF which returns two values. I have made the rounding remove decimal places, to avoid some finicky formatting issues I have around 180 angles, but the accuracy is there, the code just needs better parsing/translocation. Check my previous post in this thread for my version of arcTan()

getFacingAngle()
Code:
[h: '<!-- arg0 is the tokenID of the first arm, arg1 is the tokenID of the vertex. -->']
[
h: '<!-- uses Bone White`s arcTan UDF -->']
[
h: '<!--  macro.return is the angle you should face the arm token at using setTokenFacing() -->']

[
h: armTokenID = arg(0)]
[
h: vertexTokenID = arg(1)]
[
h, if(getTokenFacing(vertexTokenID) == ""): assert(0,"Vertex token must have a facing",0)]
[
h, if(getTokenFacing(armTokenID) == ""): assert(0,"Arm token must have a facing",0)]
[
h: armTokenX = getTokenX(0, armTokenID)]
[
h: armTokenY = getTokenY(0, armTokenID)]
[
h: vertexTokenX = getTokenX(0, vertexTokenID)]
[
h: vertexTokenY = getTokenY(0, vertexTokenID)]
[
h: xDiff = vertexTokenX - armTokenX]
[
h: yDiff = vertexTokenY - armTokenY]
[
h, if ((yDiff == 0)&&(xDiff == 0)): assert(0,"Vertex token occupies the same grid square as the arm token",0)]
[
h, if (yDiff != 0), code :{
[h: tanAngle = arcTan(xDiff/yDiff)]
[h: armTokenAngle = round(toDegrees(tanAngle), 0) + 90]
};{
[h, if(xDiff > 0): armTokenAngle = 0]
[h, if(xDiff < 0): armTokenAngle = 180]
}
]
[
h, if(yDiff < 0): armTokenAngle = armTokenAngle]
[
h, if(yDiff > 0): armTokenAngle = armTokenAngle + 180]
[
h: macro.return = armTokenAngle]

getFlankAngle()
Code:
[h: '<!-- arg0 is the tokenID of the first arm, arg1 is the tokenID of the vertex. -->']
[
h: '<!-- uses Bone White`s arcTan UDF -->']
[
h: '<!-- macro.return is the angle at which the first token faces the second.  0 degrees is from behind, 180 degrees is from infront, 90 degrees is to the side -->']

[
h: armTokenID = arg(0)]
[
h: vertexTokenID = arg(1)]
[
h, if(getTokenFacing(vertexTokenID) == ""): assert(0,"Vertex token must have a facing",0)]
[
h, if(getTokenFacing(armTokenID) == ""): assert(0,"Arm token must have a facing",0)]
[
h: armTokenX = getTokenX(0, armTokenID)]
[
h: armTokenY = getTokenY(0, armTokenID)]
[
h: vertexTokenX = getTokenX(0, vertexTokenID)]
[
h: vertexTokenY = getTokenY(0, vertexTokenID)]
[
h: xDiff = vertexTokenX - armTokenX]
[
h: yDiff = vertexTokenY - armTokenY]
[
h, if ((yDiff == 0)&&(xDiff == 0)): assert(0,"Vertex token occupies the same grid square as the arm token",0)]
[
h, if (yDiff != 0), code :{
[h: tanAngle = arcTan(xDiff/yDiff)]
[h: armTokenAngle = round(toDegrees(tanAngle), 0) + 90]
};{
[h, if(xDiff > 0): armTokenAngle = 0]
[h, if(xDiff < 0): armTokenAngle = 180]
}
]
[
h, if(yDiff < 0): armTokenAngle = armTokenAngle]
[
h, if(yDiff > 0): armTokenAngle = armTokenAngle + 180]
[
h: vertexFacing = getTokenFacing(vertexTokenID)]
[
h: flankAngle = 360-vertexFacing + armTokenAngle]
[
h, if(flankAngle >= 360): flankAngle = flankAngle - 360; flankAngle = flankAngle]
[
h, if(flankAngle >= 360): flankAngle = flankAngle - 360; flankAngle = flankAngle]
[
h, if(flankAngle > 180): flankAngle = 180 - (flankAngle - 180); flankAngle = flankAngle]
[
h: macro.return = flankAngle]

I use the UDF as follows:

Code:
[h: setTokenFacing(getFacingAngle(getInitiativeToken(),getSelected()),getInitiativeToken())]
[
r: angleOnTarget = getFlankAngle(getInitiativeToken(),getSelected())]

Just stick two tokens down, make sure each token has a facing, then move them around and use the macro.
EDIT: made the two UDF functions seperate.

_________________
How to get around the two code nest limit in MapTool (and MOTE)

 wolph42   Deity Joined: Fri Mar 20, 2009 4:40 amPosts: 9481Location: Netherlands
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]Posted: Wed Oct 17, 2012 6:31 am
you do not happen to have a function lying around that you feed x,y,r,a and that returns x2,y2 ? Preferably where a==facing angle (which is totally off in regard of the real world angle.
so
x,y one point of the line
r length of the line
a facing direction of the line where a=0 results in a vertical line upwards

e.g.
(x,y,r,a)
(0,0,50,0) returns {"x":0,"y":-50}
(10,10,50,90) returns {"x":-40,"y":10}
(20,20,40,270) returns {"x":60,"y":20}
etc.

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

 wolph42   Deity Joined: Fri Mar 20, 2009 4:40 amPosts: 9481Location: Netherlands
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]Posted: Wed Oct 17, 2012 7:04 am
Code:
[h:macro.return = strformat(
'{"x":%s,"y":%s}',
arg
)]

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 2 of 2 [ 22 posts ] Go to page Previous  1, 2

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

 Search for: Jump to: Select a forum ------------------ General    Announcements    Ideas for New Applications    General Discussion    Developer Notes       Java Programming Info    User Creations       Requests for HELLLLP!       Tilesets, Token Libraries, and Complete Maps          Token Libraries          Tilesets/Graphics for Map-making          Complete Maps       Campaign Frameworks          D&D 5e Frameworks          D&D 4e Frameworks          [D&D3.5 + Pathfinder] Campaign Macros          Shadowrun 4e Frameworks          Savage Worlds Frameworks       Published Module Support       Tutorials          Graphics, Images, Tokens, Maps          Drop-In Macros and Scripts          Campaign Frameworks       Drop-In Macro Resources    Links & External Resources    Looking For Group       "Living" Campaigns       Dungeons and Dragons       Savage Worlds       WoD       Wargaming    Documentation Requests/Discussion    Session Report-Back Tools    MapTool       How To       Macros       Feature Requests          Resolved       Bug Reports          Resolved       WIP - User FAQ       Testing    MapTool 1.4    TokenTool    DiceTool    InitiativeTool    CharacterTool       Support: d20 D&D       Support: D&D 4e       Support: Hero System       Support: Savage Worlds       Support: GURPS Other    RPTools Sightings    Running Campaigns       Thiera's College of Adventurers       Age of Might       Scales of War       Renwold       Dead Men Walking       Dark Sun - 4th Edition       Warhammer Fantasy Roleplay       Return of Uchly Namen       Insert Campaign Here       Antium       The Mystic Moon       World of Lagal       GangerRun       FB Scales of War       Sellswords of Eberron          Archive       Orbs of Chaos       World of Omegus       Keep on the Shadowfell - 4E       Rise of the Runelords       Aurith In The Age Of Steam       Widdershins       Nos's Pathfinder Campaign       Falcons Hollow       Verwirrte Welten       With it or on it       Starter Set - Jeff

### Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: No registered users and 1 guest