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 1005967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:22:55+00:00 2026-05-16T08:22:55+00:00

How can a find if a point lies within a 2D rectangle given 4

  • 0

How can a find if a point lies within a 2D rectangle given 4 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-16T08:22:56+00:00Added an answer on May 16, 2026 at 8:22 am

    Transform the point to a coordinate frame aligned with the rectangle, then the problem becomes axis-aligned and trivial.

    If the rectangle consists of the following 4 points:

    a  b
    c  d
    

    Then get the “x-axis” and “y-axis” of the rectangle as:

    x = Normalize(d-c)
    y = Normalize(a-c)
    

    Then construct a rotation matrix using x and y as columns:

    r = [ x | y ]
    

    If you’re using 3-d coordinates, we need a z axis:

    z = CrossProduct(x, y)
    r = [ x | y | z ]
    

    Your transform matrix from world coordinates to your rectangle’s axis-aligned coordinates becomes:

    T = [ r^T | -r^T * c ]
        [ 0^T |     1    ]
    

    Here we’ve chosen the lower-left corner c to be the local origin. “r^T” is r transposed. “0^T” is either a 2-d or 3-d row-vector filled with zeros. 1 is just a one. Note that this is just the inverse of the simpler rectangle-to-world transform, which is

    T^-1 = [ r   | c ]
           [ 0^T | 1 ]
    

    We can use T to transform the point to axis-aligned coordinates. Remember to pad p with a trailing 1, since T is a homogeneous matrix.

    tp = T * p;  // Don't forget to pad p with a trailing 1 before multiplying.
    
    // Checks that p isn't below or to the left of the rectangle.
    for ( int d = 0; d < num_dimensions; ++d ) {
      if ( tp[d] < 0.0 ) {
        return false;
      }
    }
    
    // Checks that p isn't to the right of the rectangle
    double width = Length(d-c);
    if ( tp[0] > width ) {
      return false;
    }
    
    // Checks that p isn't above the rectangle.
    double height = Length(a-c);
    if ( tp[1] > height ) {
      return false;
    }
    
    // p must be inside or on the rectangle.
    return true
    

    If you’re using 3d coordinates, note that the above disregards the local z value of transformed point tp. Even if p is out of the plane of the rectangle, the above behaves as if it’s been projected to the rectangle surface. If you want to check for coplanarity, just do the following beforehand:

    if ( fabs(tp[2]) > some_small_positive_number ) {
       return false;  // point is out of the rectangle's plane.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Somewhere in the user's directory is actually the correct place… May 16, 2026 at 5:38 pm
  • Editorial Team
    Editorial Team added an answer My primary task was to get html to pdf conversion… May 16, 2026 at 5:38 pm
  • Editorial Team
    Editorial Team added an answer A builder helps you construct a complex object. An example… May 16, 2026 at 5:38 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I want to find whether a point lies inside a rectangle or not. The
I can't find much information about Yii's AssetManager for the management of JS and
Short question: Given a point P and a line segment L, how do I
I'm trying to understand a paper on lossless compression of floating point numbers and
I have been trying to stream audio from a particular point by using the
I am having an issue that I can't seem to figure out. Hopefully somebody
I'm trying to print a JPanel with some painted graphics on it (overriding paintComponent).
I'm not sure if this is the right place to ask, but here goes...
my question might be a little strange. I've developed an algorithm and don't know
I have been wracking my brain to come up with a solution to this

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.