473,503 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorting a points coordinate list

440 Contributor
Hi ,

I have a list of points and I have to find the boundary nodes from the points.

For example :

pointList = [ [1.2,1.2,10],[10.5,1.3,9.5],[5,0.6,9.8],[1.1,5.0,9.2],[10.1,5.3,8.0]]

How to sort the coordinate values in the list based on X:Xmin,Xmax
Y:Ymin,Ymax,Z: Zmin and Zmax?.Is there any method or function available in Python to sort the list values based on the X ,Y and Z values

Thanks in Advance
PSB
Mar 8 '07 #1
1 10444
bvdet
2,851 Recognized Expert Moderator Specialist
Hi ,

I have a list of points and I have to find the boundary nodes from the points.

For example :

pointList = [ [1.2,1.2,10],[10.5,1.3,9.5],[5,0.6,9.8],[1.1,5.0,9.2],[10.1,5.3,8.0]]

How to sort the coordinate values in the list based on X:Xmin,Xmax
Y:Ymin,Ymax,Z: Zmin and Zmax?.Is there any method or function available in Python to sort the list values based on the X ,Y and Z values

Thanks in Advance
PSB
The list method sort() will order the list on the first element. If any two first elements are the same, then it looks at the second element. I wrote this function to sort point lists on a given attribute - x, y, or z:
Expand|Select|Wrap|Line Numbers
  1. def sortPoints(_ptlist, key='x'):
  2.     try:
  3.         if key.lower() in ['x', 'y', 'z']:
  4.             def cmpItems(a,b):
  5.                 return cmp(eval('a.'+key.lower()), eval('b.'+key.lower()))
  6.             _ptlist.sort(cmpItems)
  7.         else:
  8.             raise AttributeError, 'Invalid attribute was passed to sortPoints()'
  9.     except:
  10.         raise TypeError, 'Invalid point list'
  11.  
  12. ptList = [Point(1.0,2.0,3.0), Point(0.5,1.0,7.0), Point(12.6,-12.9,-15.6), Point(-99, 12.6, 1700),\
  13.           Point(29.6, 44.4, 19.1), Point(22.8, 12.2, 4.54)]
  14.  
  15. print formatPtList_("Unsorted points list:", ptList)
  16.  
  17. sKey = "Y"
  18. sortPoints(ptList, sKey)
  19.  
  20. print formatPtList_("Points list sorted on '%s' attribute:" % (sKey), ptList)
  21.  
  22. """
  23. Unsorted points list:
  24. X attribute         Y attribute         Z attribute         
  25. ============================================================
  26. 1                   2                   3                   
  27. 1/2                 1                   7                   
  28. 1'-0 5/8            -1'-0 7/8           -1'-3 5/8           
  29. -8'-3               1'-0 5/8            141'-8              
  30. 2'-5 5/8            3'-8 3/8            1'-7 1/8            
  31. 1'-10 13/16         1'-0 3/16           4 9/16              
  32.  
  33. Points list sorted on 'Y' attribute:
  34. X attribute         Y attribute         Z attribute         
  35. ============================================================
  36. 1'-0 5/8            -1'-0 7/8           -1'-3 5/8           
  37. 1/2                 1                   7                   
  38. 1                   2                   3                   
  39. 1'-10 13/16         1'-0 3/16           4 9/16              
  40. -8'-3               1'-0 5/8            141'-8              
  41. 2'-5 5/8            3'-8 3/8            1'-7 1/8
  42. """
You also could get the max and min values for x, y and z:
Expand|Select|Wrap|Line Numbers
  1. >>> pointList = [[1.2, 5.0, 9.1999999999999993], [1.2, 5.0, 10], [5, 0.59999999999999998, 9.8000000000000007], [10.1, 5.2999999999999998, 8.0], [10.5, 1.3, 9.5]]
  2. >>> xList = [p[0] for p in pointList]
  3. >>> yList = [p[1] for p in pointList]
  4. >>> zList = [p[2] for p in pointList]
  5. >>> map(max, [xList, yList, zList])
  6. [10.5, 5.2999999999999998, 10]
  7. >>> map(min, [xList, yList, zList])
  8. [1.2, 0.59999999999999998, 8.0]
  9. >>> 
Mar 9 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3914
by: Maarten van Reeuwijk | last post by:
I'm a newbie to Python, so sorry for this maybe trivial question. I have a numpy array with coordinates, which I want to sort, for example first on z-coordinate, then x and lastly y-coordinate. So...
3
2373
by: acosgaya | last post by:
Hi, I would like some help as how to approach the following problem: I have a set of d-dimensional points (e.g (3,5,8,9,5) is a 5-dimensional point), and I need to sort the points on each of the...
13
2528
by: JoeC | last post by:
I am completly lost. I would like to create a function that takes two vectors. These two vectors have objects with x and y coords, what I want to do find all the objects in the same x and y...
1
3036
by: jwlkr | last post by:
Hi, I am trying to sort a vector of a user defined type: a class which represents points in cartesian coordinates. The vector of points needs to be sorted according to the value of the...
9
5393
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...
4
4630
by: shortyes | last post by:
Is there any easy way to sort a list of Points by either its X or Y or both? Tried sortedlist (of String, Point) where string is Point.X & "," & Point.Y as the key sortedlist (of Point, Point)...
1
1545
by: kimt | last post by:
Hello, I am currently writing an application that involves many (> 1000) points on a (x,y) plane. I am using a struct to contain the position information, and I have the structs contained in a STL...
2
3477
by: John | last post by:
Hi there, I need to create a rectangle between two points so that I can check what is inside it using Contains(). The problem I am having is how to make the rectangle be able to cope with the...
4
1301
by: TommyC | last post by:
Hi all, Kindly need your attention here. Let say, n = 0; // number of corner points detected if (......) { corner_list.x = j; //x coordinate corner_list.y = i; //y coordinate n++;
0
7204
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
7091
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
7342
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...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.