objective c - Find total no of Close polygons iOS -
i want find total number of close shape.
in image, there 6 no of close polygons . have tried following method
(nsinteger = 0; < [arrlinesinfo count]; i++) { nsdictionary *dictlineinfo = [arrlinesinfo objectatindex:i]; startpoint = cgpointmake([[dictlineinfo valueforkey:@"line_start_point_x"] doublevalue], [[dictlineinfo valueforkey:@"line_start_point_y"] doublevalue]); endpoint = cgpointmake([[dictlineinfo valueforkey:@"line_end_point_x"] doublevalue], [[dictlineinfo valueforkey:@"line_end_point_y"] doublevalue]); [self iscircularroute:startpoint withendpoint:endpoint]; } -(void) iscircularroute:(cgpoint) linestartpoint withendpoint:(cgpoint) lineendpoint { nspredicate *pre= [nspredicate predicatewithformat:[nsstring stringwithformat:@" (self.line_end_point_x == '%f' && self.line_end_point_y == '%f') or (self.line_start_point_x == '%f' && self.line_start_point_y == '%f') or (self.line_end_point_x == '%f' && self.line_end_point_y == '%f') or (self.line_start_point_x == '%f' && self.line_start_point_y == '%f')", linestartpoint.x, linestartpoint.y, linestartpoint.x, linestartpoint.y, lineendpoint.x, lineendpoint.y, lineendpoint.x, lineendpoint.y]]; nsmutablearray *arrsamepointref = [[arrlinesinfo filteredarrayusingpredicate:pre] mutablecopy]; arrsamepointref = [[arrsamepointref filteredarrayusingpredicate:[nspredicate predicatewithformat:[nsstring stringwithformat:@" (self.line_start_point_x != '%f' && self.line_start_point_y != '%f') && (self.line_end_point_x != '%f' && self.line_end_point_y != '%f')", linestartpoint.x , linestartpoint.y , lineendpoint.x , lineendpoint.y]]] mutablecopy];//[arrsamepointref removeobject:dictlineinfo]; if(arrsamepointref.count > 2){ totalpolygon = totalpolygon + 1; } nslog(@"totalpolygon : ===== %tu", totalpolygon); (nsdictionary *dictsingleline in arrsamepointref) { cgpoint newstartpoint = cgpointmake([[dictsingleline valueforkey:@"line_start_point_x"] doublevalue], [[dictsingleline valueforkey:@"line_start_point_y"] doublevalue]); cgpoint newendpoint = cgpointmake([[dictsingleline valueforkey:@"line_end_point_x"] doublevalue], [[dictsingleline valueforkey:@"line_end_point_y"] doublevalue]); [self iscircularroute:newstartpoint withendpoint:newendpoint]; } }
this go in infinite loop.
i have start point , end point object in array. array object below
[ { "point_start_lbl" : "a", "point_end_lbl" : "b", "line_start_point_x" : 200, "line_start_point_y" : 10, "line_end_point_x" : 100, "line_end_point_y" : 10, }, ... ]
please me. in advance.
you have closed polygon if have ordered list of edges such each edge ends on vertex next starts on , no edge repeated within list.
i'm unclear data structure might therefore:
define object, edge
identifies 2 vertices.
for each vertex, create array containing every single edge touches vertex.
then, like, in swift-ish pseudocode:
var successfulpaths: [edge] = [] edge in edges { let usededges = [edge] attempttraversalfrom(edge.vertex1, edge.vertex2, usededges, successfulpaths) attempttraversalfrom(edge.vertex2, edge.vertex1, usededges, successfulpaths) } print("there \(successfulpaths.count) successful paths") [...] func attempttraversalfrom(startingvertex, endingvertex, usededges, successfulpaths) { let vertexedges = endingvertex.edges edge in (edges not in usededges) { let newendingvertex = (edge.vertex1 == endingvertex) ? edge.vertex2 : edge.vertex1 if newendingvertex == startingvertex { successfulpaths.add(usededges) return } else { let newusededges = useredges.additem(edge) attempttraversalfrom(startingvertex, newendingvertex, newusededges, successfulpaths) } } // note: automatically fall through here , return // without adding `successfulpaths` if there // no further traversable edges }
extemporaneous, etc. bit recursive part of dijkstra's pathfinding algorithm, except potential paths accumulated rather shorter paths eliminating longer ones prior complete evaluation.
Comments
Post a Comment