user3716478
user3716478

Reputation: 89

algorithm for creating shapes out of arrays

I'm looking for an algorithm which could create shapes based on arrays with coordinates. I have two 50x50 arrays: one with x and second with y coordinates.

There is always 2500 points. Then I have another 50x50 array with my values for coordinates.

I create 3 to 6 areas based on value (for example 0-100, 200-300 and 300-500). Points with certain values creates areas.

I need an algorithm which can calculate if there is only one shape in area or more and fill shapes with colors. I need that because I must fill shapes with certain colors for each area. Language is C#.

  1. Example points.
  2. Expected edges.
  3. Expected result

Example picture

Upvotes: 4

Views: 356

Answers (1)

ElKamina
ElKamina

Reputation: 7817

Basically you could use hierarchical clustering to find the clusters.

  1. Each point is its own cluster
  2. Find two cluster closest together and merge them
  3. Repeat until end condition is met

Couple of specifics: In step 2 you could use many metrics to find the closest clusters. Mean-to-mean distance or minimum distance over all point pairs are probably best choices

In Step 3, you can either stop when remaining number of clusters is 2 (or some other number). Or stop when distance is more than a threshold.

To find the actual outline, I suggest coming up with some optimization function that minimizes the length of outline while minimizing the area of the outline. And the some heuristics to optimize the function.

Something like Area - constant*Length.

Upvotes: 1

Related Questions