/// <summary> /// initialise the snake based upon a polygon shape /// </summary> /// <param name="binary_image"></param> /// <param name="BlackOnWhite"></param> /// <param name="initial_points"></param> /// <param name="max_itterations"></param> /// <param name="rnd"></param> public void Snake(bool[,] binary_image, bool BlackOnWhite, polygon2D initial_points, int max_itterations, Random rnd) { if (initial_points.x_points.Count > 1) { // get the perimeter length of the initial shape float perimeter_length = initial_points.getPerimeterLength(); // distribute points evenly along the perimeter int side_index = 0; float side_length_total = 0; for (int i = 0; i < no_of_points; i++) { // position of this point along the perimeter float perimeter_position = i * perimeter_length / no_of_points; float total = side_length_total; while (total < perimeter_position) { side_length_total = total; total += initial_points.getSideLength(side_index); if (total < perimeter_position) { side_index++; } } float side_length = initial_points.getSideLength(side_index); if (side_length > 0) { float perimeter_diff = perimeter_position - side_length_total; float fraction = perimeter_diff / side_length; float tx = 0, ty = 0, bx = 0, by = 0; initial_points.getSidePositions(side_index, ref tx, ref ty, ref bx, ref by); float dx = bx - tx; float dy = by - ty; SnakePoint[i, SNAKE_X] = tx + (dx * fraction); SnakePoint[i, SNAKE_Y] = ty + (dy * fraction); } } Snake(binary_image, BlackOnWhite, max_itterations, rnd); } }