Question

In a GIS I am given a single point and shall create a regular polygon out of it, basically exactly what this function does.

Unfortunately, I have no idea on how to achieve this. I do not even have an idea what to look for on Google.

Any ideas?

PS: The system is based on a SQL Server, hence I am using T-SQL (if this is helpful / harmful in any way).

Was it helpful?

Solution

This sounds a bit like homework, so forgive me if I layout an algorithm in plain language rather than T-SQL

First, we're going to create a polygon with n sides with radius 1 around the origin (0,0) and then show how to get to the general case of a polygon with radius r, rotation theta and center (x,y).

There will be n vertices in this n-sided polygon. Each vertex will have coordinates (cos(k/n), sin(k/n)), with k ranging from 0 to n-1. From there, to get your polygon, make a line from vertex k to vertex k+1.

Now, how do we make it bigger? If the polygon has radius r instead of radius 1, the coordinates will be (r*cos(k/n), r*sin(k/n)). Rotating it by an angle theta? (r*cos((k/n)+theta), r*sin((k/n)+theta). Translating it to somewhere other than the origin? (x+r*cos((k/n)+theta), y+r*sin((k/n)+theta).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top