chemicalx001
asked on
Find a point between 2 points...
Hi! I am using opencv and c++. I have 5 points, stored in a vector<point2f>, that i know the coordinates of. The 5th point is on a line between 2 of the others. What is the best way to find out which two?
The four are corners of a square, the fifth is somewhere on the edge of the square.
It seems like it would be simple, but I can't get my head around it.
Thanks!
The four are corners of a square, the fifth is somewhere on the edge of the square.
It seems like it would be simple, but I can't get my head around it.
Thanks!
Find the slope between the 5th point and all the other points. The slope should be the same for the two points sought. Furthermore the difference between the 5th point and the two points should have opposite signs to lie "within".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! So using your second comment, I have it working, BUT, it turns out that the line is not exact. Which is fine.
So, can i add a tolerance to this formula?
if (distance1 + distance2 == distance12)
{
cout << "distance12 wins: " << endl;
}
eg, if (a 'ALMOST' = b) or, if a is within a certain range of b?
So, can i add a tolerance to this formula?
if (distance1 + distance2 == distance12)
{
cout << "distance12 wins: " << endl;
}
eg, if (a 'ALMOST' = b) or, if a is within a certain range of b?
ASKER
ah, found it.
if (std::abs(distance1 + distance2 == distance12) < 0.01)
{
}
thanks again!
if (std::abs(distance1 + distance2 == distance12) < 0.01)
{
}
thanks again!
ASKER
I've requested that this question be closed as follows:
Accepted answer: 500 points for Saqib Husain, Syed's comment #a40711893
Assisted answer: 0 points for chemicalx001's comment #a40712000
for the following reason:
I answered my own additional question
Accepted answer: 500 points for Saqib Husain, Syed's comment #a40711893
Assisted answer: 0 points for chemicalx001's comment #a40712000
for the following reason:
I answered my own additional question
ASKER
make that:
if (std::abs((distance1 + distance2) - distance12) < 0.01)
{
}
:)
if (std::abs((distance1 + distance2) - distance12) < 0.01)
{
}
:)
You can reduce the parentheses
if (std::abs(distance1 + distance2 - distance12) < 0.01)
{
}
:)
if (std::abs(distance1 + distance2 - distance12) < 0.01)
{
}
:)
take the point with minimum x-coordinate as the start point P1. search P2 as next to P1 in x direction.
if P2 == P5 find P2 as next point in x-direction and done.
if not, set P1 = P2 and search P2 as next to P1 in y-direction.
if P2 == P5 find P2 as next point in y-direction and done.
if not, set P1 = P2 and search P2 as next to P1 in x-direction.
if P2 == P5 find P2 as next point in x-direction and done.
to handle tolerances you may round the coordinates before.
Sara
if P2 == P5 find P2 as next point in x-direction and done.
if not, set P1 = P2 and search P2 as next to P1 in y-direction.
if P2 == P5 find P2 as next point in y-direction and done.
if not, set P1 = P2 and search P2 as next to P1 in x-direction.
if P2 == P5 find P2 as next point in x-direction and done.
to handle tolerances you may round the coordinates before.
Sara
I've requested that this question be deleted for the following reason:
The question has either no comments or not enough useful information to be called an "answer".
The question has either no comments or not enough useful information to be called an "answer".
If you know that the 5th point is on a line between two adjacent corners of a square, then it suffices to determine
which side it is closest to.
This can be determined from which of the 4 midpoints it is closest to,
Or, which quadrant it is in can be determined from which side of the two diagonals it is on.
which can be determined from which of the two diagonal corners the point is closest to.
which side it is closest to.
This can be determined from which of the 4 midpoints it is closest to,
Or, which quadrant it is in can be determined from which side of the two diagonals it is on.
which can be determined from which of the two diagonal corners the point is closest to.
"Midpoint of side" seems perfect
Accept a40780458
Distances to corners in http:#a40780458 is slightly simpler than distances to midpoints,
requiring 2 comparisons instead of 3, and 8 fewer additions.
Both require 8 squaring operations.
But since it only depends on comparing distances, not adding them (like http:#a40711893) , the square root is not needed.
requiring 2 comparisons instead of 3, and 8 fewer additions.
Both require 8 squaring operations.
But since it only depends on comparing distances, not adding them (like http:#a40711893) , the square root is not needed.
ASKER
Hi, as I posted on 2015-04-08, I requested this question be closed as it was answered sufficiently.
Thanks!
Thanks!
As mentioned by the asker, #a40711893 was good enough for him