Ask Your Question

Revision history [back]

Altough the approach by @Balaji will probably work without any problems, I do think this can be done much easier. From an angle and a starting point one can use mathematics to derive the function that represents the line. Once you have done that the following steps are quite easy.

  • Define for each border (edge of mat) the value of the function. For example if your top border equals the equation x = 0, then you can define the y value of your line equation and see if that still falls within the range of your top edge.
  • For each line you want to draw there will be only 2 points possible on your matrix. This also allows you only to draw lines for 180 degrees and get all 360 degree segments. Then use those two matching points to draw your line.

Necessary equation: