473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to find the two end points in a line ...

JD
Hi,

There are about 10+ 3-D points on the same line. I want to find the two end
points from these points. The efficiency is not an issue because there are
only 10 points or so. I just need a cleaner code to do it. Should I use
an STL set to store the distances among them and then retrieve the max
distance from the last element in the set? Then the question is how to know
which points are associated with this max distance? Your help is
appreciated.

JD
Oct 8 '07 #1
5 3002
JD wrote:
There are about 10+ 3-D points on the same line. I want to find the
two end points from these points. The efficiency is not an issue
because there are only 10 points or so. I just need a cleaner code
to do it. Should I use an STL set to store the distances among them
and then retrieve the max distance from the last element in the set? Then
the question is how to know which points are associated with
this max distance? Your help is appreciated.
You should be able to use any two points to calculate the actual line
(the points should be different), then pick any point and *sort* the
other points or all points based on their relative position to the
picked one. Whether you put them all in a vector (array) and sort the
vector (array), or put them in a multiset, does not matter. The trick
is to pick the right comparison function.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 8 '07 #2
Victor Bazarov wrote:
JD wrote:
>There are about 10+ 3-D points on the same line. I want to find the
two end points from these points. The efficiency is not an issue
because there are only 10 points or so. I just need a cleaner code
to do it. Should I use an STL set to store the distances among them
and then retrieve the max distance from the last element in the set? Then
the question is how to know which points are associated with
this max distance? Your help is appreciated.

You should be able to use any two points to calculate the actual line
(the points should be different), then pick any point and *sort* the
other points or all points based on their relative position to the
picked one. Whether you put them all in a vector (array) and sort the
vector (array), or put them in a multiset, does not matter. The trick
is to pick the right comparison function.
You need only pick one of the axes (x, y, or z) and do a one time scan
for the minimum and maximum. The axis you pick needs to be one that the
line co-efficient is non zero. The way to do that is to pick two
points and find the axis with the largest absolute change.
Oct 8 '07 #3
On 2007-10-08 21:03, JD wrote:
Hi,

There are about 10+ 3-D points on the same line. I want to find the two end
points from these points. The efficiency is not an issue because there are
only 10 points or so. I just need a cleaner code to do it. Should I use
an STL set to store the distances among them and then retrieve the max
distance from the last element in the set? Then the question is how to know
which points are associated with this max distance? Your help is
appreciated.
This kinds of questions are probably better asked in a groups such as
comp.graphics.algorithms. To get the endpoints transform their
coordinates to a system in which the lines is along the X-axis (or Y or
Z if you prefer) and then find the one with the smallest and greatest
X-value.

--
Erik Wikström
Oct 8 '07 #4
On Oct 9, 12:54 am, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-08 21:03, JD wrote:
Hi,
There are about 10+ 3-D points on the same line. I want to find the two end
points from these points. The efficiency is not an issue because there are
only 10 points or so. I just need a cleaner code to do it. Should I use
an STL set to store the distances among them and then retrieve the max
distance from the last element in the set? Then the question is how toknow
which points are associated with this max distance? Your help is
appreciated.

This kinds of questions are probably better asked in a groups such as
comp.graphics.algorithms. To get the endpoints transform their
coordinates to a system in which the lines is along the X-axis (or Y or
Z if you prefer) and then find the one with the smallest and greatest
X-value.
a better way can be to calculate the the 'tangent' vector and one
point on the line,and every point on the line can be represented via a
double/float index showing how many times the 'tangent' the point is
far from specific point:

point==index*tanjent+point_0;

now you can compare/sort indices.

regards,
FM.

Oct 9 '07 #5
"JD" <jd*******@yahoo.comwrote in message
news:ra******************@newssvr13.news.prodigy.n et...
Hi,

There are about 10+ 3-D points on the same line. I want to find the two
end points from these points. The efficiency is not an issue because there
are only 10 points or so. I just need a cleaner code to do it. Should I
use an STL set to store the distances among them and then retrieve the max
distance from the last element in the set? Then the question is how to
know which points are associated with this max distance? Your help is
appreciated.
Any of the x,y or z coordinates that change will help you. If the x
coordinate changes, just find the point with the min and max x and you have
the end points. x may not change though (if the line runs along the x axis)
then you could use the y or z. You don't really need to do any math, just
detemine which of the 3 coordinates (out of any) that are changing. You
could also sort by some arbitrary method and use the max and min of that
also. The normal method I use for sorting 3d points is in pseudo code:

operator<
if ( x1 < x2 )
return true;
else if ( x1 == x2 )
if ( y1 < y2 )
return true;
else if ( y1 == y2 )
if ( z1 < z2 )
return true;
return false;
Oct 10 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: MLH | last post by:
SELECT Adresses.RawData FROM Adresses WHERE (((Adresses.RawData)=InStr(1,,Chr$(13)))); Its not doing the trick for me and I'm not sure why.
3
by: Don Pasquale | last post by:
The following function intends to delete "numberoflines" lines from a text file, named "s" (string pointer) and pointed to by file pointer "fp", starting from line "line". Now, the function...
4
by: Marc Dansereau | last post by:
Hi all, I wonder what is the most efficient way to generate random point on a line defined by 2 double points (x0,y0) and (x1,y1). Here is the pseudocode of my method : for each point {...
90
by: Bret Pehrson | last post by:
This message isn't spam or an advertisement or trolling. I'm considering farming some of my application development to offshore shops (I'm in the US). I have absolutely *no* experience w/ this,...
1
by: balakrishnan.dinesh | last post by:
Hi frnds, Im creating function to plot line graph in javascript . I have marked the points in graph. but what i need to do is, i want to draw the line between those marked point, but i dont...
1
by: ambr | last post by:
i made a program for grading true and false test,there are no syntax error but program is not running like it should be itshould give me student's ID followed by the answer,followed by test score...
9
by: Eric.Gabrielson | last post by:
Hello, I am very knew to python and am attempting to write a program in python that a friend of mine is having to write in java. I am doing this for fun and would like some help as to how i can...
1
by: tiffrobe | last post by:
I'm a little lost on my program. Everything works fine except function 3. It gives out garbage numbers. Its suppose to give the distance between two points and then the area of 2 circles. ...
3
by: raylopez99 | last post by:
I suspect the answer to this question is that it's impossible, but how do I make the below code work, at the point where it breaks (marked below). See error CS0411 This is the complete code. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.