220 likes | 320 Views
Generation Of Random Digital Curve in 2-D. Submitted By Amit Samanta, Sougata Singha, Souvik Pal. Algorithm for 2-Dimension. Basic Features. 4 Connectivity, can be extended to 8 connectivity No Backtracking, choses points on the fly Simple Data Structure Complexity ~ O(n)
E N D
Generation Of Random Digital Curve in 2-D Submitted By Amit Samanta, Sougata Singha, Souvik Pal
Basic Features • 4 Connectivity, can be extended to 8 connectivity • No Backtracking, choses points on the fly • Simple Data Structure • Complexity ~ O(n) • Direction of movement: • 0: Right • 1: Up • 2: Left • 3: Down 1 2 0 3
Basic Features Data Structure Used – For each Point • Integer ‘val’ – to denote if this point is visited or not • Char ‘prev’ and ‘next’ – to track the previous and next move to/from that point • Boolean array Turn[4] – to validate each of 4 neighbours of a point
Algorithm • Initially all the points are unvisited. • Select a Seed Point P from user. • Set seed point as Current Point P’. • Select a valid and safe neighbor P” randomly. • Modify the ‘next’ and ‘prev’ values of P’ and P” accordingly.
Algorithm • Set the selected point P” as current point P’. • Mark P’ as visited. • Check if current point P’ is uni-distant from seed point P. • In that case, select P as neighbor of P’ and close the graph. • Otherwise goto step 4.
Key Concepts • Selection of a neighbor point depends on the outcome of an random draw. • A neighbor is valid if it is not been visited earlier. • A move to a neighbor is safe if does not enter in any endless loop. • No extra care is taken to close the curve. Eventually it will be closed within (NxM)+1 moves.
Randomness • At each point, the next possible move is generated by a random number generator. • Uses system function rand(). • Modifies the seed with srand() to increase randomness.
Validity • All the randomly generated points are not valid. • A point is valid if it is not visited early, or • If the point is not a restricted point • E.g. Points outside the boundary
Safe Move • Initially all the points in the plane are safe. • First the seed point is made visited. One of its neighbor is selected from the draw, here safe move is not considered. • For each point P, we select a random neighbor P’. Consider the neighbor’s 4 neighbors (a,b,c,d).
Safe Move • If any of them (except P) is visited, consider the movement of the graph at that point from the prev and next values. • Also consider the corner points if they are visited. • Checking the movements, we discard some neighbors.
Safe Move • Check if there is any safe neighbor of P’ or not. • If P’ has no safe neighbor, donot move to P’. • Re-draw, and select another neighbor of P and follow the same procedure.
The Digital Plane Four Neighbors Randomly Selected Seed Point It is Safe and We Move Is this Safe Move ?
invalidate Consider another situation, where some of its neighbors are visited Check the prev and next values Similar situations for corner points invalidate invalidate If there is any valid neighbors, actually make the move