A function to determine four directions on a map depends on the type of map,
And whether I give absolute or relative directions.
Map 1 - split the rows and pack each row into individual arrays.
Map 2 - depending on the maximum length of the array: which contains as many lines as possible.
90 lines x 90 columns (8100 coordinates, maximum of 8192 coordinates)
The maps differ only in the number and length of the array (s).
For four directions the new coordinates correspond to a certain calculation.
The directional change requires only the position and the angle to the new position.
The relative direction is added to the old direction and determined by the sinus and the cosine on a map.
Eg .: to the left
- take the old angle add to the new angle (0 + = - 90)
- take the sinus of 0 ° and the cosine of 0 °, compute X and Y coordinate
- the negative sine determines Y
- The cosine determines X
An example (on map 2):
Code: Select all
set /a coordinate=103
set /a moveX =+1 ^
, moveY =+15^
, angle =+90^
, direction =0 ^
, "circle =360"^
, "Left =-(Right=angle)"^
, negativeY =-180
set "direction=(direction=Left +direction %%circle)"
set /a "coordinate+=(((%direction% +negativeY) /angle %%2) *moveY + ((direction -angle) /angle %%2) *moveX)"
I know it looks somewhat complicated.
With sinus and cosinus, I can calculate eight directions when the angle is 45 °
[ posY -=sin(direction) *1.4122 *moveY ]
[ posX =cos(direction) *1.4122 *moveX ]
Code: Select all
Set / a posY =%sin(x):x=direction% * 141422/100000 *moveY
Cosine is mirrored at 45 ° to the sinus
Cos(x) = sin( (-x-45) * -1 + 45 )
But I do not come with the sinusfunktion on the result of the respective angle.
I have already read all posts about sinus and kosinus.
Among others I have read the following articles:
viewtopic.php?f=3&t=5819&hilit=cos
viewtopic.php?f=3&t=5824&p=42648&hilit=cos
viewtopic.php?f=3&t=4896&p=49822&hilit=fastes+sin#p49822
The results are actually between minus 1 and plus 1. Either I have not understood the use of the function, or the decisive part of the calculation is still missing.
Code: Select all
setlocal enableDelayedExpansion
REM APA mod: Convert final sine calculation into a long "function" expression
REM http://www.dostips.com/forum/viewtopic.php?f=3&t=6744
set "a=(a=(x)%%62832)"
set "c=(c=(%a%>>31|1)*a)"
set "t=(t=((%c%-47125)>>31)+1)"
set "a=a-=%t%*((a>>31|1)*62832) +^^^^^^^!t*((((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a))"
set "SIN(x)=%a%,a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/18752"^
"*a/15360*a/15625*a/15625*a/16000*a/44800000"
for %%i in (a c t) do set "%%i="
set /a "posY-=%sin(x):x=40%"
set /a "posX=%sin(x):x=(-40-45)*-1+45%
Is that the conversion from sin to cosinus?
15708-angle
Because where I am straight I unfortunately come no further. Is there a simple explanation of how I can use the function sinus in batch?
Phil