c# - Sorting an array of polyLines -


i have following 2 classes

public class pointclass {     double x, y, z; }   

and

public class polylineclass {     pointclass startpoint;     pointclass endpoint; } 

and array of polylineclasses

polylinearray[]; 

assume if connect lines in polylinearray in kind of order, obtain closed, nonselfintersecting curve.

for example

                  startpt  endpt polylinearray[0]: (0,0,0) (1,0,0) polylinearray[1]: (0,1,0) (0,0,0) polylinearray[2]: (1,1,0) (0,1,0) polylinearray[3]: (1,0,0) (1,1,0) 

if traverse through array in 0->3->2->1 order, create closed curve(in simple case, square). right now, have following algorithm:

1) int = 0;  2) endpt of polylinearray[i]; 3) search through array element index j such     polylinearray[i].endpoint == polylinearray[j].startpoint. 4) = j; repeat step2 until elements in array have been visited. 

the above algorithm o(scary). there more efficient way sorting? if language matter, coding in c#.

create class

public class endpoint {     pointclass point ;     int lineindex ; } 

and array

endpoint endpoints[] ; 

whose length twice of polylinearray.

for each end point e of line i create endpoint {e,i} , add endpoints array. sort array in point element order. (the points can sorted/compared component-wise).

after sort complete, can traverse array , pick off endpoints. these come in pairs, points equal, line indices point lines join @ point. can walk sorted endpoint array picking linked series of polylines.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -