RPTools.net

Discussion and Support

Skip to content

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






Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

Previous topic | Next topic 

  Print view

Author Message
User avatar  Offline
Deity
 
Joined: Tue Nov 10, 2009 6:11 pm
Posts: 8009
Location: Bay Area
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]
PostPosted: 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.

_________________
Downloads:


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9481
Location: Netherlands
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]
PostPosted: 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

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
User avatar  Offline
Great Wyrm
 
Joined: Tue Aug 23, 2011 10:41 am
Posts: 1134
Location: Cornwall, UK
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]
PostPosted: 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)


Top
 Profile  
 
User avatar  Offline
Great Wyrm
 
Joined: Tue Aug 23, 2011 10:41 am
Posts: 1134
Location: Cornwall, UK
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]
PostPosted: 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.

Top
 Profile  
 
User avatar  Offline
Great Wyrm
 
Joined: Tue Aug 23, 2011 10:41 am
Posts: 1134
Location: Cornwall, UK
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]
PostPosted: 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)


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9481
Location: Netherlands
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]
PostPosted: 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

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9481
Location: Netherlands
 Post subject: Re: MathLib - SOHCAHTOA [Update 1/8/11]
PostPosted: Wed Oct 17, 2012 7:04 am 
never mind already got it:
Code:
[h:macro.return = strformat(
'{"x":%s,"y":%s}', 
arg
(0) + round(arg(2)*math.cos(math.toRadians(arg(3)+90)),0),
arg(1) - round(arg(2)*math.sin(math.toRadians(arg(3)+90)),0)
)]
 

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

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

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

Search for:

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





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman