473,657 Members | 2,283 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 10467
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
3918
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 an array like: , , , ] should look after sorting like , , , ]
3
2385
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 coordinates. The algorithm that I am trying to implement says that the resulting data structure is a multi-pointer list ((d-1)tuply threaded list), each node of which is threaded in each of the single pointer lists corresponding to the chosen...
13
2544
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 coords and put all the objects in the same coordinate together.
1
3050
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 x-coordinate. I am trying to use the "sort" function defined in algorithms.h and I am getting a segmentation fault. I have inlined the code below. Can someone please tell me what I am doing wrong ? I am compiling this code on linux ( fedora 6 x86_64 using...
9
5402
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 generate random coordinate points (x,y) and compare them with user inputted coordinate points. For example how will I be able to access the separate values, the x from the x,y position. I think I understand everything except 1)the random coordinate...
4
4634
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) using the Point as the key I could always use try and true method of a binary search algorithm but I rather not.
1
1552
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 vector. Given a target coordinate (x,y)_t, I would like to be able to cycle through the vector of points in order to obtain the closest point. What would be the most efficient way to implement this? I have considered keeping the vector sorted...
2
3510
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 angle between the two points, see the image in the link for what I mean. http://homepage.ntlworld.com/andrew.baldock/bloodbowl/select.png I am not interested in displaying anything in the rectangle, I just need
4
1308
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
8323
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.