Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5966847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:51:28+00:00 2026-05-22T19:51:28+00:00

Given an irregular polygon and a point within that polygon, how do I determine

  • 0

Given an irregular polygon and a point within that polygon, how do I determine which edge in the polygon is closest to the point?

Example

I will likely have to run this calculation for a large set of points within the polygon (e.g. 50-200 points).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:51:29+00:00Added an answer on May 22, 2026 at 7:51 pm
    1. Calculate closest point on the line that is tangent to each edge of the polygon.
    2. Calculate closest point on each line segment (edge of the polygon) to the point in question.
    3. Calculate the distance from the closest point on each line segment to the point in question.
    4. Find the minimum distance. The corresponding polygonedge with the minimum distance is the answer.

    Each step of this algorithm is linear time (O(n)).

    Here are the basic formulas for each of the steps:

    Calculate closest point on the line that is tangent to each edge of the polygon.

    • Let the one endpoint of an edge of a polygon be p1 = {x1, y1}.
    • Let the other endpoint of an edge of a polygon be p2 = {x2, y2}.
    • Let the point in the polygon you are analyzing be p3 = {x3,y3}.
    • Let u be the percentage of the distance between p1 and p2, that is needed to find the point on the line formed by p1 and p2, such that p1+u(p2-p1) = the point on the line that is closest to p3 (the line segment between this point and p3 also happens to be perpendicular to the line going through p1 and p2).
    • u = ((x3 - x1)(x2 - x1)+(y3 - y1)(y2 - y1)) / ((x2 - x1)^2 + (y2 - y1)^2)
    • Let the point closest to p3 on the line formed by p1 and p2 be known as pu = {xu, yu}
    • xu = x1 + u (x2 - x1)
    • yu = y1 + u (y2- y1)
    • And like we said before pu = {xu, yu}
    • Repeat these calculations for every polygon edge (i.e. substitute in new p1s and p2s)

    Calculate closest point on each line segment (edge of the polygon) to the point in question.

    The point pu is only the closest point on the line segment when 0 <= u <= 1. Otherwise the appropriate endpoint of the line segment is the closest point to the point in question. Thus for each pu, p1, p2, and u calculated in the above step do the following:

    • Let pc = {xc, yc} be denoted as the closest point on the line segment of the polygon edge to the point in question.
    • IF u<0 THEN pc = p1
    • ELSE IF u>1 THEN pc = p2
    • ELSE pc = pu

    Calculate the distance from the closest point on each line segment to the point in question.

    • Distance between p3 and pc = `sqrt((x3 – xc)^2 + (y3 – yc)^2)
    • Repeat this calculation for all pc’s

    Find the minimum distance. The corresponding polygonedge with the minimum distance is the answer.

    • Iterate through all of the distances until you find the smallest one. The corresponding polygon edge is the answer.

    Here is a diagram to help you understand what the points and terminology in this post represent:

    enter image description here

    ….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a (source) patch file, what's the easiest way to apply this patch on
Given this HTML: <ul id=topnav> <li id=topnav_galleries><a href=#>Galleries</a></li> <li id=topnav_information><a href=#>Information</a></li> </ul> And this
Given a table where the first column is seconds past a certain reference point
I am looking for REGEX which will give me data along with the end
Given an XML layout like this, I'm trying to create a XSD schema to
Given a table that has a column of string timestamps (yyyyMMddHHmmssSSS format), I want
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given a Python object of any kind, is there an easy way to get
Given a select with multiple option's in jQuery. $select = $(<select></select>); $select.append(<option>Jason</option>) //Key =
Given a DateTime representing a person's birthday, how do I calculate their age in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.