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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:34:06+00:00 2026-05-17T01:34:06+00:00

How can I check if a point is below a line or not ?

  • 0

How can I check if a point is below a line or not ?

I’ve the following data:

Line [ {x1,y1}, {x2,y2} ]
Points {xA,yA}, {xB,yB} ...

I need to write a small algorithm in python to detect points on one side and the other side of the line.

thanks

  • 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-17T01:34:07+00:00Added an answer on May 17, 2026 at 1:34 am

    You could try using a cross product — http://en.wikipedia.org/wiki/Cross_product.

    v1 = (x2-x1, y2-y1)   # Vector 1
    v2 = (x2-xA, y2-yA)   # Vector 2
    xp = v1[0]*v2[1] - v1[1]*v2[0]  # Cross product (magnitude)
    if xp > 0:
        print('on one side')
    elif xp < 0:
        print('on the other')
    else:
        print('on the same line!')
    

    You’d need to calibrate what each side is. If you want it to be "below" or "above" you need to ensure the points on the line are sorted horizontally.

    I haven’t tested this.

    Edit I initially put in the dot product formula. 😮

    Edit 2 D’oh, I was putting the coordinates into a set instead of a tuple. Using namedtuple('point', 'x y') for the vectors is nice if you’re running a reasonably modern version of Python.

    Luckily I found Calculating a 2D Vector's Cross Product.

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

Sidebar

Related Questions

I'm using mechanize/cookiejar/lxml to read a page and it works for some but not
I'm currently teaching myself Python and was just wondering (In reference to my example
I had no clue why this doesn't work. The following Function is created by
I am having a cookie problem in the below example. the cookie does get
I'm using PHP's SwiftMailer library to bulk send emails (following CANSPAM and RFCs). Everything
I have an array of pointers that point to arrays of ints. I have
I have below probably a bunch of problems but let's simplify them with easier
Is there anyway to remove several consecutive commits in a branch ? Let's says
I'm working on a client portal at the moment and with the help of
I'm using Process.Start() to initialize an elevated copy of the currently running application. Unfortunately

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.