Skip to content

Instantly share code, notes, and snippets.

@songritk
Created September 12, 2017 08:54
Show Gist options
  • Save songritk/b13fa1b68f374d8ad8140e7beb080286 to your computer and use it in GitHub Desktop.
Save songritk/b13fa1b68f374d8ad8140e7beb080286 to your computer and use it in GitHub Desktop.
Convert MCS to random approximate (X,Y) coordination
#!/bin/bash
. math.sh
if ! [ $# -eq 1 ]; then
echo "./mcs2xy.sh <mcs index>"
exit
fi
platform='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
platform='linux'
elif [[ "$unamestr" == 'FreeBSD' ]]; then
platform='freebsd'
elif [[ "$unamestr" == 'Darwin' ]]; then
platform='osx'
fi
## Table
## | MCS | Range(m) |
## | 0 | < 1200 |
## | 1 | < 800 |
## | 2 | < 600 |
## | 3 | < 400 |
## | 4 | < 300 |
## | 5 | < 170 |
## | 6 | < 150 |
## | 7 | < 100 |
## | 8 | < 50 |
#declare -a Range=('1200' '800' '600' '400' '300' '170' '150' '100' '50')
declare -a Range=('100' '80' '70' '60' '50' '40' '30' '20' '10')
mcs=$1
if [[ "$platform" == "osx" ]]; then
if [ $mcs -eq 8 ]; then
r=`jot -r 1 1 ${Range[$mcs]}`
else
r=`jot -r 1 ${Range[$(($mcs+1))]} ${Range[$mcs]}`
fi
theta=`jot -r 1 0 360`
else
if [[ "$mcs" -eq 8 ]]; then
r=`shuf -i 1-${Range[$mcs]} -n 1`
else
r=`shuf -n 1 -i ${Range[$(($mcs+1))]}-${Range[$mcs]}`
fi
theta=`shuf -n 1 -i 0-360`
fi
#echo $r $theta
s=`sin $theta`
c=`cos $theta`
x=`echo "$r*$c"|bc`
y=`echo "$r*$s"|bc`
echo "$x $y"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment