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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:04:20+00:00 2026-05-22T22:04:20+00:00

A line is defined by two end points P1[x1, y1], P2[x2, y2]. Let Q

  • 0

A line is defined by two end points P1[x1, y1], P2[x2, y2]. Let Q [xq, yq] be a tested point. Both coordinates are double.

Differencies:

dx1 = x2 - x1
dy1 = y2 - y1
dx2 = xq - x1
dy2 = yq - y1

Norms

double n1_sq = sqrt(dx1 * dx1 + dy1 * dy1);
double n2_sq = sqrt(dx2 * dx2 + dy2 * dy2);

My assumption: test with normalized vectors is less sensitive to rounding errors

double test = (dx1 / n1_sq  )  * (dy2 / n2_sq) - ( dx2 / n2_sq ) * ( dy1 / n1_sq );

than

double test = dx1 * dy2 - dx2 * dy1;

The problem arises in the following cases:

A) A tested point is Q is on the line

Q = [0.5(x1 + x2), 0.5(y1 + y2)]

In many cases, the result is not zero, but

test >> 0

B) Inappropriate configuration of the line/ tested point

Case 1) long segment:

Let us move the tested point to the start point, dist (Q, |p1, p2|) = 7e-4

P1 = [0, 0]
P2 = [1000000000.00001, 1000000000.00001]
Q = [0.0,0.001] 

Normalized test: 0.7
Unnormalized test: 1.0e+6

Case 2) long segment:

Let us move the tested point to the end point dist (Q, |p1, p2|) = 7e-4

P1 = [0, 0]
P2 = [1000000000.00001, 1000000000.00001]
Q = [1000000000.0, 1000000000.001] 

Normalized test: 5.0e-13
Unnormalized testt: 1.1 e+6

Case 3) short segment:

Let us move the tested point to the start point, dist (Q, |p1, p2|) = 7e-4

P1 = [0, 0]
P2 = [0.00001, 0.00001]
Q = [0.0,0.001] 

Normalized test: 0.7
Unnormalized test: 1.0e-8

Results:

A) The normalized test for long segments is less reliable. The Case 2 could be considered as machinery zero with the following decision: Q is on |p1, p2|…

B) For short segments, the situation is reversed, an unnormalized test gives a machinery zero.

But result of both tests are not constant and the resulted value does not bring any information about real distance of the point Q from the line |p1, p2|. Using a threshold in both tests does not bring a correct result… And the value of the threshold can not be determined before..

What should I do?

My solution is to replace both test with the new test: test the distance of point Q and line P1, p2 and using some threshold eps. Point Q with

dist (Q,|P1,P2|) < eps,  (for example 1e-10) 

will be placed on the line P1, P2… The result of the test does not depend on configuration of points (ie if we move the test point Q along the segment P1, P2)

Is anyone using a better test or have a different solution of this problem?

  • 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-22T22:04:21+00:00Added an answer on May 22, 2026 at 10:04 pm

    I don’t understand your test. It doesn’t seem to involve the coordinates of Q at all. Also, for two values u and v, the norm is computed with minimum rounding as M * sqrt(1 + m / M), where M = max(|u|, |v|) and m = min(|u|, |v|). As for a dist function, that is the best approach, although you might want to make the threshold a function of the line segment length. It really depends on your application.

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

Sidebar

Related Questions

I am trying to find out if a line defined by two points is
This is really a double question, my two end goals having answers to: What
Am I being dense here? StreamReader.ReadLine states that: A line is defined as a
The Cassandra command-line utility sstablekeys can be used to extract all defined row keys
I need a function to find the shortest distance between two line segments. A
I'm computing the ordinate y of a point on a line at a given
I have a line that I draw in a window and I let the
I define a collection that is supposed to map two parts of a line
I want to comment a line using the pre-processor: #define open /##* #define close
line = english: while french: pendant que spanish: mientras german: whrend words = line.split('\t')

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.