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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:59:55+00:00 2026-05-15T00:59:55+00:00

Greetings, I am trying to bin an array of points (x, y) into an

  • 0

Greetings,

I am trying to bin an array of points (x, y) into an array of boxes [(x0, y0), (x1, y0), (x0, y1), (x1, y1)] (tuples are the corner points)

So far I have the following routine:

def isInside(self, point, x0, x1, y0, y1):
    pr1 = getProduct(point, (x0, y0), (x1, y0))
    if pr1 >= 0:
        pr2 = getProduct(point, (x1, y0), (x1, y1))
        if pr2 >= 0:
            pr3 = getProduct(point, (x1, y1), (x0, y1))
            if pr3 >= 0:
                pr4 = getProduct(point, (x0, y1), (x0, y0))
                if pr4 >= 0:
                    return True
    return False

def getProduct(origin, pointA, pointB):
    product = (pointA[0] - origin[0])*(pointB[1] - origin[1]) - (pointB[0] - origin[0])*(pointA[1] - origin[1])
    return product

Is there any better way then point-by-point lookup? Maybe some not-obvious numpy routine?

Thank you!

  • 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-15T00:59:56+00:00Added an answer on May 15, 2026 at 12:59 am

    Are these boxes axis aligned? i.e. are the edges parallel to the coordinate axes? If so this can be done quite efficiently with vectorized comparisons on NumPy arrays.

    def in_box(X, B):
        """
        Takes an Nx2 NumPy array of points and a 4x2 NumPy array of corners that 
        form an axis aligned box.
        """
        xmin = B[:,0].min(); xmax = B[:,0].max()
        ymin = X[:,1].min(); ymax = X[:,1].max()
        return X[X[:,0] > xmin & X[:,0] < xmax & X[:,1] > ymin & X[:,1] < ymax]
    

    amending to >= and <= if you prefer them to be inclusive.

    If you need it for an arbitrary quadrilateral, matplotlib actually has a routine matplotlib.nxutils.points_inside_poly that you could use (if you have it installed) or else copy it (it’s BSD-licensed). See this page for a discussion of the algorithms used and other algorithms for inside-a-polygon tests.

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

Sidebar

Related Questions

Greetings, I have the following layout in Android. I'm trying to make it so
Greetings! I'm trying to have a UIWebView controlled from generated events. Is there a
Hi there and greetings to all, I am trying to have a checkbox for
Greetings All, I have a SQLite database that I'm trying to add a new
Greetings, everyone. I'm trying to learn some Silverlight basics, and have decided to write
Greetings from some noob trying to learn JQuery, I am attempting to make it
Greetings, Trying to sort through the best way to provide access to my Entity
Greetings, I am trying to learn pointers in C, I simply want my addtwo
Greetings Friends, I am trying to overlay the simple 2D game I am developing
Greetings, I am trying to perform a copy from one vector (vec1) to another

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.