More

How do I query for all polygons within a distance from a point?

How do I query for all polygons within a distance from a point?


Call me stupid, but somehow I couldn't figure out how to do the following.

I've got a testing shapefile with 18 features, which I successfully imported into GeoDjango (1.3, running on Spatialite). As an practical example, I've taken a centroid of one of them (area.mpoly.centroid) and tried to find all areas within a 20 km distance (touching would be enough, needn't cover complete area).

Area.objects.filter(mpoly__dwithin=(centroid, D(km=20)))

However, this only gives me an empty list. Increasing the number to 200 km (in theory, this should cover all of my dataset) also yields nothing.

Am I doing something wrong?


I missed this before, you're using SpatialLite. dwithin is not supported with SpatialLite.


Old answer: 'Area' is a GeoDjango class. You probably have a name conflict. Don't name your models with the same name of any GeoDjango classes.

Also, 'centroid' should not be used as a variable name for the same reason.


Insert geojson polygons into mongodb and query, based on the coordinates of a point, all the polygons which are located at a certain distance from it

I need some help on: how to insert geojson polygons into a mongodb database and query, based on the coordinates of a certain point, all the polygons which are located at a certain distance from that point

Here is the geojson sample I will use:

I want to save it into the mongodb database and be able to query it. For this, I do the following:

I create a mongoose schema:

I create a mongoose model:

var GeoModel = mongoose.model('GeoModel', GeoSchema)

I save the geojson to my database:

var post = new GeoModel(testJson)

And, finally I search and find the record:

The issues I need help with:

I will load lots and lots geojson data in the form of polygons.

Lets say I am located at the following coordinates: 40.8003, -73.9580

For a distance of x kilometers, I want to be able all the polygons that are in range.

So, I am thinking of doing a query similar to this, which of course is not working :):


2 Answers 2

This is an incredibly late answer, but perhaps I can shed some light on a solution. The "set" number you refer to is a Spatial Reference Indentifier or SRID. For lat/long calculations you should consider setting this to 4326, which will ensure metres are used as a unit of measurement. You should also consider switching to SqlGeography rather than SqlGeometry, but we'll continue with SqlGeometry for now. To bulk set the SRID, you can update your table as follows:

For a single radius, you need to create a radii as a spatial object. For example:

STBuffer() takes the spatial point and creates a circle (now a Polygon type) from it. You can then query your data set as follows:

The above will now use any Spatial Index you have created on the [SpatialColumn] in its query plan.

There is also a simpler option which will work (and still use a spatial index). The STDistance method allows you to do the following:

Lastly, working with a collection of radii. You have a few options. The first is to run the above for each radii in turn, but I would consider the following to do it as one:

The final above has not been tested, but I'm 99% sure it's just about there with a small amount of tweaking being a possibility. The ideal of taking the min radius distance in the select is that if the multiple radii stem from a single location, if a point is within the first radius, it will naturally be within all of the others. You'll therefore duplicate the record, but by grouping and then selecting the min, you get only one (and the closest).

Hope it helps, albeit 4 weeks after you asked the question. Sorry I didn't see it sooner, if only there was only one spatial tag for questions.


3 Answers 3

A slow version (without spatial indexes):

To make use of the spatial indexes, you need to denormalize your table so that each polygon vertex is stored in its own record.

Then create the SPATIAL INDEX on the field which contains the coordinates of the vertices and just issue this query:

The things will be much more easy if you store UTM coordinates in your database rather than latitude and longitude.

I don't think there's a single answer to this. It's generally a question of how to organize your data so that it makes use of the spacial locality inherent to your problem.

The first idea that pops into my head would be to use a grid, assign each point to a square, and check select the square the point is in, and those around it. If we're talking infinite grids, then use a hash-value of the square, this would give you more points than needed (where you have collisions), but will still reduce the amount by a bunch. Of course this isn't immediately applicable to polygons, it's just a brainstorm. A possible approach that might yield too many collisions would be to OR all hashed values together and select all entries where the hashes ANDed with that value is non-zero (not sure if this is possible in MySQL), you might want to use a large amount of bits though.

The problem with this approach is, assuming we're talking spherical coordinates (lat, long generally does) are the singularities, as the grid 'squares' grow narrower as you approach the poles. The easy approach to this is. don't put any points close to the poles. :)


ors_geocode() transforms a description of a location provided in query , such as the place’s name, street address or postal code, into a normalized description of the location with a point geometry. Additionally, it offers reverse geocoding which does exactly the opposite: It returns the next enclosing object which surrounds the coordinates of the given location . To obtain more relevant results you may also set a radius of tolerance around the requested coordinates.

This service allows you to find places of interest around or within given geographic coordinates. You may search for given features around a point, path or even within a polygon specified in geometry . To list all the available POI categories use ors_pois('list') .

You can gather statistics on the amount of certain POIs in an area by using request='stats' .


Parameters

The features that will be evaluated against the Selecting Features parameter values. The selection will be applied to these features.

Specifies the spatial relationship to be evaluated.

  • Intersect — The features in the input layer will be selected if they intersect a selecting feature. This is the default.
  • Intersect 3D — The features in the input layer will be selected if they intersect a selecting feature in three-dimensional space (x, y, and z).
  • Intersect (DBMS) —The features in the input layer will be selected if they intersect a selecting feature. This option applies to enterprise geodatabases only. The selection will be processed in the enterprise geodatabase DBMS rather than on the client when all requirements are met (see more information in the usage notes). This option may provide better performance than performing the selection on the client.
  • Within a distance — The features in the input layer will be selected if they are within the specified distance (using Euclidean distance) of a selecting feature. Use the Search Distance parameter to specify the distance.
  • Within a distance geodesic —The features in the input layer will be selected if they are within a specified distance of a selecting feature. Distance between features will be calculated using a geodesic formula that takes into account the curvature of the spheroid and correctly handles data near and across the dateline and poles. Use the Search Distance parameter to specify the distance.
  • Within a distance 3D — The features in the input layer will be selected if they are within a specified distance of a selecting feature in three-dimensional space. Use the Search Distance parameter to specify the distance.
  • Contains — The features in the input layer will be selected if they contain a selecting feature.
  • Completely contains — The features in the input layer will be selected if they completely contain a selecting feature.
  • Contains Clementini — This spatial relationship yields the same results as Completely contains with the exception that if the selecting feature is entirely on the boundary of the input feature (no part is properly inside or outside), the feature will not be selected. Clementini defines the boundary polygon as the line separating inside and outside, the boundary of a line is defined as its end points, and the boundary of a point is always empty.
  • Within — The features in the input layer will be selected if they are within a selecting feature.
  • Completely within — The features in the input layer will be selected if they are completely within or contained by a selecting feature.
  • Within Clementini — The result will be identical to Within with the exception that if the entirety of the feature in the input layer is on the boundary of the feature in the selecting layer, the feature will not be selected. Clementini defines the boundary polygon as the line separating inside and outside, the boundary of a line is defined as its end points, and the boundary of a point is always empty.
  • Are identical to — The features in the input layer will be selected if they are identical (in geometry) to a selecting feature.
  • Boundary touches — The features in the input layer will be selected if they have a boundary that touches a selecting feature. When the input features are lines or polygons, the boundary of the input feature can only touch the boundary of the selecting feature, and no part of the input feature can cross the boundary of the selecting feature.
  • Share a line segment with — The features in the input layer will be selected if they share a line segment with a selecting feature. The input and selecting features must be line or polygon.
  • Crossed by the outline of — The features in the input layer will be selected if they are crossed by the outline of a selecting feature. The input and selecting features must be lines or polygons. If polygons are used for the input or selecting layer, the polygon's boundary (line) will be used. Lines that cross at a point will be selected lines that share a line segment will not be selected.
  • Have their center in — The features in the input layer will be selected if their center falls within a selecting feature. The center of the feature is calculated as follows: for polygon and multipoint, the geometry's centroid is used for line input, the geometry's midpoint is used.

The features in the Input Features parameter will be selected based on their relationship to the features from this layer or feature class.

The distance that will be searched. This parameter is only valid if the Relationship parameter is set to Within a distance , Within a distance geodesic , Within a distance 3D , Intersect , Intersect 3D , Have their center in , or Contains .

If the Within a distance geodesic option is selected, use a linear unit such as kilometers or miles.

Specifies how the selection will be applied to the input and how it will be combined with an existing selection. This tool does not include an option to clear an existing selection use the Clear the current selection option on the Select Layer By Attribute tool to do that.

  • New selection — The resulting selection will replace any existing selection. This is the default.
  • Add to the current selection — The resulting selection will be added to an existing selection. If no selection exists, this is the same as the New selection option.
  • Remove from the current selection — The resulting selection will be removed from an existing selection. If no selection exists, the operation will have no effect.
  • Select subset from the current selection — The resulting selection will be combined with the existing selection. Only records that are common to both remain selected.
  • Switch the current selection — The selection will be switched. All records that were selected will be removed from the selection, and all records that were not selected will be added to the selection. The Selecting Features and Relationship parameters are ignored when this option is selected.

Specifies whether the spatial relationship evaluation result or the opposite result will be used. For example, this parameter can be used to get a list of features that do not intersect or are not within a given distance of features in another dataset.

  • Unchecked—The query result will be used. This is the default.
  • Checked—The opposite of the query result will be used. If the Selection Type parameter is used, the reversal of the selection occurs before it is combined with existing selections.

Derived Output

The updated inputs with selections applied.

The names of the updated inputs.

The number of selected records.

The features that will be evaluated against the select_features parameter values. The selection will be applied to these features.

Specifies the spatial relationship to be evaluated.

  • INTERSECT — The features in the input layer will be selected if they intersect a selecting feature. This is the default.
  • INTERSECT_3D — The features in the input layer will be selected if they intersect a selecting feature in three-dimensional space (x, y, and z).
  • INTERSECT_DBMS — The features in the input layer will be selected if they intersect a selecting feature. This option applies to enterprise geodatabases only. The selection will be processed in the enterprise geodatabase DBMS rather than on the client when all requirements are met (see usage notes). This option may provide better performance than performing the selection on the client.
  • WITHIN_A_DISTANCE — The features in the input layer will be selected if they are within the specified distance (using Euclidean distance) of a selecting feature. Use the search_distance parameter to specify the distance.
  • WITHIN_A_DISTANCE_3D — The features in the input layer will be selected if they are within a specified distance of a selecting feature in three-dimensional space. Use the search_distance parameter to specify the distance.
  • WITHIN_A_DISTANCE_GEODESIC — The features in the input layer will be selected if they are within a specified distance of a selecting feature. Distance between features will be calculated using a geodesic formula that takes into account the curvature of the spheroid and correctly handles data near and across the dateline and poles. Use the search_distance parameter to specify the distance.
  • CONTAINS — The features in the input layer will be selected if they contain a selecting feature.
  • COMPLETELY_CONTAINS — The features in the input layer will be selected if they completely contain a selecting feature.
  • CONTAINS_CLEMENTINI — This spatial relationship yields the same results as COMPLETELY_CONTAINS with the exception that if the selecting feature is entirely on the boundary of the input feature (no part is properly inside or outside), the feature will not be selected. Clementini defines the boundary polygon as the line separating inside and outside, the boundary of a line is defined as its end points, and the boundary of a point is always empty.
  • WITHIN — The features in the input layer will be selected if they are within a selecting feature.
  • COMPLETELY_WITHIN — The features in the input layer will be selected if they are completely within or contained by a selecting feature.
  • WITHIN_CLEMENTINI — The result will be identical to WITHIN with the exception that if the entirety of the feature in the input layer is on the boundary of the feature in the selecting layer, the feature will not be selected. Clementini defines the boundary polygon as the line separating inside and outside, the boundary of a line is defined as its end points, and the boundary of a point is always empty.
  • ARE_IDENTICAL_TO — The features in the input layer will be selected if they are identical (in geometry) to a selecting feature.
  • BOUNDARY_TOUCHES — The features in the input layer will be selected if they have a boundary that touches a selecting feature. When the input features are lines or polygons, the boundary of the input feature can only touch the boundary of the selecting feature, and no part of the input feature can cross the boundary of the selecting feature.
  • SHARE_A_LINE_SEGMENT_WITH — The features in the input layer will be selected if they share a line segment with a selecting feature. The input and selecting features must be line or polygon.
  • CROSSED_BY_THE_OUTLINE_OF — The features in the input layer will be selected if they are crossed by the outline of a selecting feature. The input and selecting features must be lines or polygons. If polygons are used for the input or selecting layer, the polygon's boundary (line) will be used. Lines that cross at a point will be selected lines that share a line segment will not be selected.
  • HAVE_THEIR_CENTER_IN — The features in the input layer will be selected if their center falls within a selecting feature. The center of the feature is calculated as follows: for polygon and multipoint, the geometry's centroid is used for line input, the geometry's midpoint is used.

The features in the Input Features parameter will be selected based on their relationship to the features from this layer or feature class.

The distance that will be searched. This parameter is only valid if the overlap_type parameter is set to WITHIN_A_DISTANCE , WITHIN_A_DISTANCE_GEODESIC , WITHIN_A_DISTANCE_3D , INTERSECT , INTERSECT_3D , HAVE_THEIR_CENTER_IN , or CONTAINS .

If the WITHIN_A_DISTANCE_GEODESIC option is selected, use a linear unit such as kilometers or miles.

Specifies how the selection will be applied to the input and how it will be combined with an existing selection. This tool does not include an option to clear an existing selection use the CLEAR_SELECTION option on the Select Layer By Attribute tool to do that.

  • NEW_SELECTION — The resulting selection will replace any existing selection. This is the default.
  • ADD_TO_SELECTION — The resulting selection will be added to an existing selection. If no selection exists, this is the same as the NEW_SELECTION option.
  • REMOVE_FROM_SELECTION — The resulting selection will be removed from an existing selection. If no selection exists, the operation will have no effect.
  • SUBSET_SELECTION — The resulting selection will be combined with the existing selection. Only records that are common to both remain selected.
  • SWITCH_SELECTION — The selection will be switched. All records that were selected will be removed from the selection, and all records that were not selected will be added to the selection. The select_features and overlap_type parameters are ignored when this option is selected.

Specifies whether the spatial relationship evaluation result or the opposite result will be used. For example, this parameter can be used to get a list of features that do not intersect or are not within a given distance of features in another dataset.

  • NOT_INVERT — The query result will be used. This is the default.
  • INVERT — The opposite of the query result will be used. If the selection_type parameter is used, the reversal of the selection occurs before it is combined with existing selections.

Derived Output

The updated inputs with selections applied.

The names of the updated inputs.

The number of selected records.

Code sample

The following Python window script demonstrates how to use the SelectLayerByLocation function in immediate mode.

The following stand-alone script shows how to use the SelectLayerByLocation function in a workflow to extract features to a new feature class based on location and an attribute query.

The following stand-alone script shows a variety of uses of the overlap_type parameter's WITHIN_A_DISTANCE and WITHIN_A_DISTANCE_GEODESIC options with the search_distance parameter.


Mesh Generation

Marshall Bern , Paul Plassmann , in Handbook of Computational Geometry , 2000

1.1 Types of geometric domains

We divide the possible inputs first according to dimension — two or three. We distinguish four types of planar domains, as shown in Figure 1 . For us, a simple polygon includes both boundary and interior. A polygon with holes is a simple polygon minus the interiors of some other simple polygons its boundary has more than one connected component. A multiple domain is more general still, allowing internal boundaries in fact, such a domain may be any planar straight-line graph in which the infinite face is bounded by a simple cycle. Multiple domains model objects made from more than one material. Curved domains allow sides that are algebraic curves such as splines. As in the first three cases, collectively known as polygonal domains, curved domains may or may not include holes and internal boundaries.

Fig. 1 . Types of two-dimensional inputs: (a) simple polygon, (b) polygon with holes, (c) multiple domain, and (d) curved domain.

Three-dimensional inputs have analogous types. A simple polyhedron is topologically equivalent to a ball. A general polyhedron may be multiply connected, meaning that it is topologically equivalent to a solid torus or some other higher genus solid it may also have cavities, meaning that its boundary may have more than one connected component. We do assume, however, that at every point on the boundary of a general polyhedron a sufficiently small sphere encloses one connected piece of the polyhedron’s interior and one connected piece of its exterior. Finally, there are multiple polyhedral domains — general polyhedra with internal boundaries — and three-dimensional curved domains, which typically have boundaries defined by spline patches.

Construction and modeling of domain geometry lie outside the scope of this chapter, so we shall simply assume that domains are given in some sort of boundary representation, without specifying the exact form of this representation. Computational geometers typically assume exact, combinatorial data structures, such as linked lists for simple polygons and polygons with holes, doubly connected edge lists [ 103 ] or quad-edge structures [ 63 ] for planar multiple domains, and winged-edge structures [ 44 , 62 ] for polyhedral domains.

In practice, complicated domains are designed on computer aided design (CAD) systems. These systems use surface representations designed for visual rendering, and then translate the final design to another format for input to the mesh generator. The Stereolithography Tessellation Language (STL) file format, originally developed for the rapid prototyping of solid models, specifies the boundary as a list of surface polygons (usually triangles) and surface normals. The advantages of the STL input format are that a “watertight” model can be ensured and model tolerance (deviation from the CAD model) can be specified by the user. The Initial Graphics Exchange Specification (IGES) format enables a variety of surface representations, including higher-order representations such as B-splines and NURBs. Perhaps due to its greater complexity, or to sloppy CAD systems or users, IGES files often contain incorrect geometry (either gaps or extra material) at surface intersections.

An alternative approach to format translation is to directly query the CAD system with, say, point-enclosure queries, and then construct a new representation based on the answers to those queries. This approach is most advantageous when the translation problem is difficult, as it may be in the case of implicit surfaces (level sets of complicated functions) or constructive solid geometry formulas.

With either approach, translation or reconstruction by queries, the CAD model must be topologically correct and sufficiently accurate to enable meshing. We expect to see greater integration between solid modeling and meshing in the future.


SDO_NN_DISTANCE

Description

Returns the distance of an object returned by the SDO_NN operator. Valid only within a call to the SDO_NN operator.

Keywords and Parameters

Value Description
number Specifies a number that must be the same as the last parameter passed to the SDO_NN operator.
Data type is NUMBER.

This operator returns the distance of an object returned by the SDO_NN operator. In determining how near two geometry objects are, the shortest possible distance between any two points on the surface of each object is used.

Usage Notes

SDO_NN_DISTANCE is an ancillary operator to the SDO_NN operator. It returns the distance between the specified geometry and a nearest neighbor object. This distance is passed as ancillary data to the SDO_NN operator. (For an explanation of how operators can use ancillary data, see the section on ancillary data in the chapter on domain indexes in the Oracle9i Data Cartridge Developer's Guide.)

You can choose any arbitrary number for the number parameter. The only requirement is that it must match the last parameter in the call to the SDO_NN operator.

Use a bind variable to store and operate on the distance value.

The following example finds the two objects from the SHAPE column in the COLA_MARKETS table that are nearest to a specified point (10,7), and it finds the distance between each object and the point. (The example uses the definitions and data from Section 2.1.)

Note the following about this example:

1 is used as the number parameter for SDO_NN_DISTANCE, and 1 is also specified as the last parameter to SDO_NN (after 'sdo_num_res=2' ).

The column alias dist holds the distance between the object and the point. (For geodetic data, the distance unit is meters for non-geodetic data, the distance unit is the unit associated with the data.)

Related Topics


1.7 Querying Spatial Data

After you have created and populated spatial tables, updated the spatial metadata, and created spatial indexes, you can use Oracle Locator operator and functions to perform location-based queries. This section shows some queries to find the closest customers to a store and all customers within a specified distance of a store.

Example 1-5 shows the SQL statement and the output for finding the three closest customers to the store with the STORE_ID value of 101. This example uses the SDO_NN ("nearest neighbors") operator.

Example 1-5 Finding Closest Customers to a Store

The /*+ordered*/ hint is a hint to the optimizer, which ensures that the STORES table is searched first.

The SDO_NN operator returns the SDO_NUM_RES value of the customers from the CUSTOMERS table who are closest to store 101. The first argument to SDO_NN (c.cust_geo_location in the example) is the column to search. The second argument to SDO_NN (s.storeh_geo_location in the example) is the location you want to find the neighbors nearest to. No assumptions should be made about the order of the returned results. For example, the first row returned is not guaranteed to be the customer closest to store 101. If two or more customers are an equal distance from the store, either of the customers may be returned on subsequent calls to SDO_NN.

When you use the SDO_NUM_RES parameter, no other constraints are used in the WHERE clause. SDO_NUM_RES takes only proximity into account. For example, if you added a criterion to the WHERE clause because you wanted the five closest customers that resided in NY, and four of the five closest customers resided in NJ, the preceding query would return one row. This behavior is specific to the SDO_NUM_RES parameter, and its results may not be what you are looking for.

Example 1-6 extends Example 1-5 by showing the SQL statement and the output (reformatted for readability) for finding the three closest customers to the store with the STORE_ID value of 101, and ordering the results by distance (in meters) from the store. This example uses the SDO_NN_DISTANCE ancillary operator.

Example 1-6 Finding Closest Customers, Ordered by Distance from Store

The index(c customers_sidx) hint is required here to force the spatial index on the CUSTOMERS table to be used, because of a problem in this release with spatial queries that use an ORDER BY clause.

The SDO_NN_DISTANCE operator is an ancillary operator to the SDO_NN operator it can only be used within the SDO_NN operator. The argument for this operator is a number that matches the number specified as the last argument of SDO_NN in this example it is 1. There is no hidden meaning to this argument it is simply a tag. With SDO_NN_DISTANCE, you can order the results by distance and guarantee that the first row returned is the closest. If the data you are querying is stored as longitude and latitude, the default unit for SDO_NN_DISTANCE is meters.

The SDO_NN operator also has a unit parameter that determines the unit of measurement returned by SDO_NN_DISTANCE however, it is not used in this example.

The ORDER BY distance clause ensures that the distances are returned in order, with the shortest distance first.

Example 1-7 shows the SQL statement and the output for finding all customers within 100 miles of the store with the STORE_ID value of 101. This example uses the SDO_WITHIN_DISTANCE operator.

Example 1-7 Finding Customers Within 100 Miles of a Store

The SDO_WITHIN_DISTANCE operator returns the customers from the customers table that are within 100 miles of store 101. The first parameter to SDO_WITHIN_DISTANCE ( c.cust_geo_location in the example) is the column to search. The second parameter ( s.store_geo_location in the example) is the location from which you want to determine the distances. No assumptions should be made about the order of the returned results. For example, the first row returned is not guaranteed to be the customer closest to store 101.

The distance keyword specifies the distance value (100 in this example).

The unit keyword specifies the unit of measure for the distance keyword. The default unit is the unit of measure associated with the data. For longitude and latitude data, the default is meters however, in this example it is miles.


Constructing a Time Series Graph

To construct a time series graph, we must look at both pieces of our paired data set. We start with a standard Cartesian coordinate system. The horizontal axis is used to plot the date or time increments, and the vertical axis is used to plot the values of the variable that we are measuring. By doing this, we make each point on the graph correspond to a date and a measured quantity. The points on the graph are typically connected by straight lines in the order in which they occur.


12 Answers 12

Any polygon (regular or not) can be described by an equation involving only absolute values and polynomials. Here is a small explanation of how to do that.

Let's say that a curve $C$ is given by the equation $f$ if we have $C = <(x,y) in mathbb^2, , f(x,y) = 0>$.

If $C_1$ and $C_2$ are given by $f_1$ and $f_2$ respectively, then $C_1 cup C_2$ is given by $f_1 . f_2$ and $C_1 cap C_2$ is given by $f_1^2 + f_2^2$ (or $|f_1| + |f_2|$). So if $C_1$ and $C_2$ can be described by an equation involving absolute values and polynomials, then so do $C_1 cup C_2$ and $C_1 cap C_2$.

If $C = <(x,y) in mathbb^2, , f(x,y) ge 0>$, then $C$ is given by the equation $|f|-f$.

Now, any segment $S$ can be described as $S = <(x,y) in mathbb^2, , a x + b y = c, , x_0 le x le x_1, , y_0 le y le y_1>$, which is given by a single equation by the above principles. And since union of segments also are given by an equation, you get the result.

EDIT : For the specific case of the octagon of radius $r$, if you denote $s = sin(pi/8)$, $c = cos(pi/8)$, then one segment is given by $|y| le rs$ and $x = rc$, for which an equation is

$f(x, y) = left||rs - |y|| - (rs - |y|) ight| + |x-rc| = 0$

So I think the octagon is given by

To get a general formula for a regular polygon of radius $r$ with $n$ sides, denote $c_n = cos(pi/n)$, $s_n = sin(pi/n)$ and

$f_n(x+iy) = left||rs_n - |y|| - (rs_n - |y|) ight| + |x-rc_n|$

then your polygon is given by

Depending on $n$, you can use symmetries to lower the degree a bit (as was done with $n = 8$).

Here's a parametric equation I have made for a regular $n$-gon, coded in R:

This equation is actually just the polar equation for the line through the point $(1,0)$ and $(cos(2pi/n),sin(2pi/n))$ which contains one of the edges. By restricting the range of the variable $ heta$ to the interval $[0,2pi/n[$, you will in fact just get that edge. Now, we want to replicate that edge by rotating it repeatedly through an angle $2pi/n$ to get the full polygon. But this can also be achieved by using the modulus function and reducing all angles to the interval $[0,2pi/n[$. This way, you get the polar equation I propose.

So, using polar plots and the modulo function, it's pretty easy to make regular $n$-gons.

Here is another parametric equation for a regular $n$-gon with unit radius:

$eginx&=cosleft(frac ight)cosleft(frac(2lfloor u floor+1) ight)-(2u-2lfloor u floor-1)sinleft(frac ight)sinleft(frac(2lfloor u floor+1) ight)y&=cosleft(frac ight)sinleft(frac(2lfloor u floor+1) ight)+(2u-2lfloor u floor-1)sinleft(frac ight)cosleft(frac(2lfloor u floor+1) ight)end$

The provenance of this set is a bit more transparent if we switch to matrix-vector notation:

$egincosleft(frac(2lfloor u floor+1) ight)&-sinleft(frac(2lfloor u floor+1) ight)sinleft(frac(2lfloor u floor+1) ight)&cosleft(frac(2lfloor u floor+1) ight)endegincosleft(frac ight)(2u-2lfloor u floor-1)sinleft(frac ight)end$

and we see that the construction involves rotating and copying the line segment joining the points $(cosleft(frac ight),pmsinleft(frac ight))$ $n$ times around a circle.

Here's sundry Mathematica code:

The following is probably not in the spirit of the game, but what about a parametric equation? If we are willing to use complex numbers to represent points in the plane, we could use $z=texp(2pi ik/n) +(1-t)exp(2pi i(k+1)/n),qquad 0 le t<1,quad k=0, 1, dots, n-1$

When n' = n/2 and % is the modulus operator.

It would work just as well with cosecant as with secant.

Also the apothem would be 1 and the radius sec(-π/n).

$arcsin left(sin left(left[sin left(60cdot frac<180> ight)left(frac><3>cdot x+y ight),x ight] ight) ight)+left(frac<1><3> ight)cdot arcsin left(sin left(left[cos left(30cdot frac<180> ight)left(x-frac><3>y ight),y ight]cdot sqrt<3> ight) ight)=0$

I came up with this to plot a hexagon tessellation in desmos. the [list] funct "hides" the overlay . so it isn't really a single EQ. actually there was very little info on this. took me weeks. enjoy

Reposted from PolymathProgrammer.com, my answer to my own initial query. Generated mostly on my own after some initial help from a friend (Jason Schmurr) and my dad (Russell Gmirkin)

I believe I've solved my own inquiry. The following are functions that, when graphed in polar coordinates render lovely polygons.

In fact, I’ve got 3 versions (6 if you consider rotation a factor to either align a vertex or the midpoint of a side with $ heta=0$). One with circumradius = 1 (as vertices $ o infty$, polygons expand outward toward the circumscribed circle), one with apothem = 1 (as vertices $ o infty$, polygons collapse inward toward the inscribed circle) and one with the midpoint between circumradius & apothem = 1 (as vertices $ o infty$, both the maxima and minima, thus the circumscribed and inscribed circles, collapse toward that ‘midpoint radius’).

I’d be interested to know whether this approach, describing the radius of a polygon as a periodic function, has any precedent (has anyone else done this, or am I the first)? I’ve been working on this idea for some time (on and off for years), but just recently overcame some stumbling blocks with a little help from a friend and my dad. Most of the legwork was my own, though.

The relatively final form(s) appear to be:

(n-gon, circumradius=1, unrotated)
1/(((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[(v*x)/4]]+((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(Pi/2)]]-((Sec[pi/v]-1)/(Sec[Pi/4]-1))+1)

(n-gon, circumradius=1, rotated $-pi/4$)
1/(((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(Pi/4)]]+((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(3Pi/4)]]-((Sec[pi/v]-1)/(Sec[Pi/4]-1))+1)

(n-gon, function centered around unit circle, unrotated)
((Sec[Pi/v]+1)/2)/(((Sec[Pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)]]+((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(Pi/2)]]-((Sec[pi/v]-1)/(Sec[Pi/4]-1))+1)

(n-gon, function centered around unit circle, rotated $-pi/4$)
((Sec[Pi/v]+1)/2)/(((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(Pi/4)]]+((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(3Pi/4)]]-((Sec[pi/v]-1)/(Sec[Pi/4]-1))+1)

(n-gon, apothem=1, unrotated)
Sec[Pi/v]/(((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[(v*x)/4]]+((Sec[pi/v]-1)/(Sec[Pi/4]-1))Abs[Cos[((v*x)/4)-(Pi/2)]]-((Sec[pi/v]-1)/(Sec[Pi/4]-1))+1)

Don’t know whether they simplify at all to something less complicated… Even if not, they’re beauties!

If it's a unique solution and I'm first to it, I submit these as the Gmirkin Polygon Radius Function(s) (or some suitably nifty sounding name that’s not too cumbersome). *Smile* Heh.

I may write them up formally for publication at some point, once a few previous engagements clear up, assuming they’ve not previously been published or some directly correlated function has already been published elsewhere. (If so, I’d like to know when, where and by whom for academic curiosity’s sake.)

It is my belief that a similar function exists for describing 3D Polyhedrons of some description(s). Though, I have not yet even attempted such a case and will probably stick to 2D cases for now. I can also tell you that if you vary the phase shift of the denominator [Abs[Cos[]]] terms by differing amounts (though not both by some multiple of $pi/4$, $pi/2$, etc.), you can also reproduce rectangles, isosceles triangles, etc. In some cases you can also generate diamond shapes by varying some other parameters. It's s surprisingly robust solution, as I'd hoped. Lord knows it's taken me a few years of false starts to get at the correct combination of functions. Though, I learned plenty along the way, much of which helped me generalize to all polygons from the square case a friend solved at my behest a week or two ago.

Here's hoping this is an interesting, unique new solution that's viable and notable. (One can hope!)

Sorry the post is a bit lengthy. )

Sorry. Jumped the gun slightly.

I retract the above equations. At the behest of someone on another site, I checked in Wolfram Alpha at a few data points. While it appears to work for the Square case (where the coefficients and corrective term basically cancel out), it doesn't work for other cases, but is slightly off. I think I've got the coefficients wrong. Will have to poke around a bit more in the maths to see if it's possible to get a technically correct exact solution.

The graphs were so close as to fool me into thinking they were exact for all cases. Will get back to you if/when I get a technically correct solution. 'Til then. I still believe there is a valid function, since the Square case is technically correct @ 1/(Abs[Sin(x)]+Abs[Cos[x]]) or 1/(Abs[Cos[x]]+[Abs[Cos[x-(Pi/2)]]]) . Just need the technically correct coefficient. will work on it as I've got some time. But, for now, the incorrect versions are darned close! o) Enough to fool most people (including me, apparently).


Watch the video: Selecting all polygons with a distance from a point using ArcMap