-2

I am creating an application and for that I have to find the coordinates any freeshape. I have tried to implement that but I am not able to identify all the coordinates.

I have the coordinate value of the boundary of shape in array.

Like there was any shape then how can I find out all the coordinates inside this and put them in the list<Point>.

  • 1
    Are you concerned about speed? If not, just write a simple loop to check if the rasterized output has a bright pixel, and append to a list. – Mateen Ulhaq Oct 15 '18 at 06:48
  • I don't understand can you please explain a bit – Chandrapal Singh Jhala Oct 15 '18 at 06:50
  • You want to get all the pixels inside the shape? – Magnus Oct 15 '18 at 06:52
  • Yes but the shape can be anything. – Chandrapal Singh Jhala Oct 15 '18 at 06:53
  • Is this for image rendering purposes? – Magnus Oct 15 '18 at 06:53
  • 1
    Possible duplicate of : https://stackoverflow.com/questions/6486499/determine-if-a-point-sits-inside-an-arbitrary-shape. unless you are asking about the ray casting itself. – roozbeh S Oct 15 '18 at 06:54
  • 1
    yes it is for image processing after getting the coordinates I have to find the pixel value of image on that coordinates. – Chandrapal Singh Jhala Oct 15 '18 at 06:54
  • 1
    I still dont get it, why do you need _all_ the pixels? What is the end goal? – Magnus Oct 15 '18 at 06:55
  • What do the pixels have to do with temperature? – Mateen Ulhaq Oct 15 '18 at 06:59
  • If you were using any other language, I'd simply multiply your thermal conductivity map with this image. In the long term, you might consider using a [library](https://stackoverflow.com/questions/2336701/recommendation-for-c-sharp-matrix-library) or language with better numerical support (C++, Python, ...). – Mateen Ulhaq Oct 15 '18 at 07:04
  • What's the nature of the `Point` structure you;re working with? Is it using integers or floats to represent coordinates? If the latter, realise that there isn't usually "a" set of points in a given area - you need to decide what granularity of points you want to work with, and almost always it's not the lowest representable for your range of values. – Damien_The_Unbeliever Oct 15 '18 at 07:39

1 Answers1

1

EDIT: From what I understand, you want to multiply the interior of your shape by a thermal conductivity map that corresponds with each pixel.

I'd recommend:

  • Floodfill the interior of your shape. (See image processing libraries such as AForge.NET.)
  • Perform an element-wise multiplication it with your thermal conductivity map. (See numerical libraries.)

The result is a heatmap of "temperature". You can process it further as desired.


If you're not concerned about speed, take the rasterized output and simply check for the presence of a bright pixel:

var img = /* some 2D array */;
var list = new List<Tuple<int, int>>();

foreach ((var row, var j) in img.Select((x, i) => Tuple.Create(x, i))) {
    foreach ((var pixel, var i) in row.Select((x, i) => Tuple.Create(x, i))) {
        if (pixel == 255) {
            list.Add(Tuple.Create(i, j));
        }
    }
}

Perhaps a LINQ version:

img
    .Select((r, j) => new {row = r, j = j})
    .Select((t, j) => t.row
        .Select((p, i) => new {p = p, i = i, j = j})
        .Where(t => t.p == 255)
        .Select(t => Tuple.Create(t.i, t.j)))
    .SelectMany(x => x);

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135