find a line go through the center mass and that line must be inside object area I have an object (orange color object) and I know its centroid/center mass C. I want program to automatically find another point ( can be point 1, point 2, point 3 or point 4 and so on) such that the line connect point C and one of those points (so as green line in figure 2) must stay inside the object. Moreover, the green line length must be as long as possible, or at least 3/4 of the maximum length. The yellow point in figure bottom is not qualified because the violet line which connect it to the center mass C has a part which is not inside the object.

Any idea? I am doing it on Matlab (image processing)
How about:


Separate the foreground from the background and keep a list of indices or a logical mask from the background
Convert the image to a (rho, theta) coordinate space, meaning that each pixel is encoded by the angle and length of vector from the origin to itself. You can scan along this vector to see if you encounter any background pixels. Have a look at the so-called Trace Transform
Alternatively you can stay in the original coordinate domain and use Bresenham's line algorithm to get all pixels belonging to a scan-line between a point and the center and then comparing them against the list of background labeled pixels.


Perhaps you can optimize a bit by starting on the edge of the foreground shape, working your way inward to the center, discarding any scan-line the moment it encounters a background labeled pixel.