Create polygon around dot

Dear Masters,

Kindly need your help to solve my issue..
My goal is create a polygon around "dot" (x,y coordinate)

lets say we have some dot as below (these coordinates have meter as unit)

588237.20     5768355.50
588337.90      5768402.50
588459.70      5768436.00
588584.30       5768464.00
588653.80       5768470.50
588679.10       5768465.00

And I want to create polygong around dot which has radius 150 meters.

my logical is
for every dot, if dot has x_ori and y_ori, i have to calculate every 2 degree (0-360 degree) for x_calculated and y_calculated.

polygon1 : x_ori + x_calculated1 , y_ori + y_calculated1
polygon2 : x_ori + x_calculated2 , y_ori + y_calculated2
to
polygon181 : x_ori + x_calculated181 , y_ori + y_calculated181

where 
x_calculated1 = 150*cos ((0*pi)/180)
x_calculated2 = 150*cos ((2*pi)/180)
x_calculated3 = 150*cos ((4*pi)/180)
to
x_calculated181 = 150*cos ((360*pi)/180)

and

y_calculated1 = 150*sin ((0*pi)/180)
y_calculated2 = 150*sin ((2*pi)/180)
y_calculated3 = 150*sin ((4*pi)/180)
to
y_calculated181 = 150*sin ((360*pi)/180)
 

whereas

pi is 3.14159265359

Thank you for your helps..
Ipatah

I'd try it in awk:

awk '{ for(N=0; N<360; N+=2) { 
        A=(2*3.14159*N)/360;
        print "Point "N" is ", $1+15*cos(A), $2+15*sin(A);
} }' inputfile
1 Like

May I propose to add BEGIN {Pi=4*atan2(1,1)} and then use Pi for optimal precision?

1 Like
$ echo asdf | awk '{ print 4*atan2(1,1); }'
3.14159
$
echo asdf | awk '{ printf "%20.20f\n", 4*atan2(1,1); }'
3.14159265358979311600

Default output fmt is "%.6g"

---------- Post updated at 23:00 ---------- Previous update was at 22:48 ----------

Also:

awk -v OFMT="%.15f" 'BEGIN {Pi=4*atan2(1,1); print sin(Pi); print sin (3.14159)}' 
0.000000000000000
0.000002653589793
1 Like

The accuracy difference between the two Pi values equates to about 4 microns over the 150 meter radius.

Since the OP's datafile only goes to mm precision it is probably all moot and 22/7 will do quite nicely,

2 Likes

thank for your helps Masters...

---------- Post updated at 10:05 PM ---------- Previous update was at 08:01 AM ----------

Hi Masters,

I have tried the script and thank you that is works, Here I need more improvement. I edit a script from Corona688 as below

awk '{ for(N=0; N<=360; N+=2) { A=(2*3.14159*N)/360; printf "circle %20.3f%20.3f\n", $1+150*cos(A), $2+150*sin(A); } }' inputfile

but I need to add numbering at the end of raw (increasing for every input coordinate) as output example below

for 2 input coordinate

767996.759989 88392.0959787
770043.399989 87148.8058945 

And I should get output as below

circle 768146.759  88392.095  1
circle 768146.668  88397.330  1
circle 768146.394  88402.559  1
circle 768145.938  88407.775  1
...................
................... 
circle 768145.300  88371.219  1
circle 768145.938  88376.415  1
circle 768146.394  88381.631  1
circle 768146.668  88386.860  1
circle 770193.399  87148.805  2
circle 770193.308  87154.040  2
circle 770193.034  87159.269  2
circle 770192.578  87164.485  2
..............
................
circle 770192.578  87133.125  2
circle 770193.034  87138.341  2
circle 770193.308  87143.570  2
circle 770193.399  87148.805  2

thanks for your helps,
ipatah

Try this:

awk '{ for(N=0; N<=360; N+=2) {
    A=(2*3.14159*N)/360; 
    printf "circle %20.3f%20.3f %d\n", $1+150*cos(A), $2+150*sin(A), FNR;
}}' inputfile
1 Like