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

  • SEARCH
  • Home
  • 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 8051193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:14:59+00:00 2026-06-05T07:14:59+00:00

I was wondering if the following algorithm to check if a point is inside

  • 0

I was wondering if the following algorithm to check if a point is inside a rectangle is valid.
I’ve developed it using my own intuition (no strong trig/math basis to support it), so I’d love to hear from someone with more experience in the matter.

Context:

  • The rectangle is defined with 4 points. It could be rotated.
  • Coordinates are always positive.
  • By definition, the point is considered inside the rectangle if intersects it.

Hypothesis:

  • Use the distance between the point and the rectangle vertices (first diagram below).
  • The maximum possible total distance is when the point is in one vertex (second diagram).
  • If the point is just outside the rectangle, the distance will be greater (third diagram).

Diagram link: http://i45.tinypic.com/id6o35.png

Algorithm (Java):

static boolean pointInsideRectangle(Point[] rect, Point point) {
    double maxDistance = distance(rect[0], rect[1]);
    maxDistance += distance(rect[0], rect[2]);
    maxDistance += distance(rect[0], rect[3]);

    double distance = 0;
    for (Point rectPoint : rect) {          
        distance += distance(rectPoint, point);
        if (distance > maxDistance) return false;
    }
    return true;
}

Questions: is this correct?

  • 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-06-05T07:15:01+00:00Added an answer on June 5, 2026 at 7:15 am

    Short answer: NO 😛 (don´t fell bad about it)

    Long Answer: Intersecction the areas from the four circles that you mention (max distance between opposite vertex) does not produce a rectangle.Common area of four circles of radius equal to the rectangle´s diagonal with center in each corner
    Since I´m a bit rusty in geometry I can´t give full mathematical explanation (time constrain for my part), but give you some pseudocode of the procedure with the constrains that you ask (no fancy formulae), valid for any rectangle the wikipeida or a geometry book can fill the gaps.

    • Find the N,E,S,W vertex (the uppermost, rightmost, lowest and leftmost vertex) this is trivially easy for any rectangle but the axis aligned who can produce oddly assignation of the vertex (see images with examples) enter image description here
    • Find the NE, SE, SW and NW border, this is the line equation in wikipedia or another link, again should be easy, but the axis aligned border should be analized carefully because those generate another type of ecuation/restriction.
    • Check if your point is on the “right side” of the border see inequality as mathematical term, only a point inside your rectangle satisfy the four restrictions as you can see in the image attached. for each "border" the green area present a valid place for the point

    • my apologies if I have overlook some command of java.geom that can accomplish this task

    I hope this help with your endevour

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

Sidebar

Related Questions

Just wondering if there was a nice (already implemented/documented) algorithm to do the following
Hi I am using the following insertion sort algorithm and I would like to
Consider the following pretty simple C++ code: #include <algorithm> #include <iostream> using namespace std;
I'm wondering about an algorithm solving the following (efficiently): A 2D matrix of numbers
I was wondering if the following scenario is possible using htaccess rules. I want
I was wondering about some other valid alternative to the XOR Bit-Level encryption algorithm.
I'm wondering if the following style of capture by reference is valid: struct Foo
The following mergesort is from Data Structures and Algorithm Analysis (Weiss). What I'm wondering
Hi I am using the following generic bubble sort algorithm and I would like
Wondering if following will work for google in robots.txt Disallow: /*.action I need to

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.