Tejasvi Tarone
Tejasvi Tarone

Reputation: 1

How to find r,theta using x,y coordinates in shell script

I wrote this code but didn't get the output

#!/bin/bash

echo $1 $2
x=$1
y=$2
#echo "sum is $(($x+$y))"
#z=echo "r is $((($1*$1)+($2*$2)))"
#print z
z=$((($x*$x)+($y*$y)))
a=$((($y)/($x)))
echo "scale=5; sqrt($z)" | bc
b=`echo - | awk '{print (('$a' * 3.14159))}'`
k=`echo - | awk '{print (tan('$y'))}'`
echo $k

Upvotes: 0

Views: 167

Answers (1)

M. Nejat Aydin
M. Nejat Aydin

Reputation: 10133

#!/bin/bash

bc -l <<< "x=$1; y=$2; sqrt(x*x + y*y); a(y/x)"

The first line of the output is r and the second line is theta in radians.

Upvotes: 1

Related Questions