algorithm - How many integer points within the three points forming a triangle? -


In fact this is a classic problem because SO user has put it (another in which during an interview Work to ask)

I could not do it in an hour (breath), so what is the algorithm that calculates the integer digits within the triangle?

Edit : Assuming the corners are on the integer coordinates (otherwise it becomes a problem finding all the points within the triangle and then by reducing all the floating points, only the integer points Is left with; less elegant problem).

Explain that the corners are in integer coordinates, by making a rectangle around the triangles explained by the skin scales. Can get answers.

The rectangle for the AJAX, the number of internal digits

  I = (j - 1) (K - 1).  

For the 5x3 rectangle below, there are 8 internal points.

A vertical leg (J) and a horizontal foot (K) number of internal points for the triangle

  I = ((J - 1) (K - 1) - h) / 2  

Where H is the number of edges of the rectangle, which corresponds to the triangle of the triangle (not the length).

A vertical side or a horizontal side for the triangle, the number of interior points (I) is given by

Where j, k, h1, h2, and b are marked in the following picture

Finally, without a vertical or horizontal side, the case of triangle divided into two sub-cases Where there are three triangles in the area around a triangle, and where the surrounding area consists of three triangles and a rectangle See the picture given below).

The first sub-case is given by the number of internal digits (I)

by the variable A marked in the following picture E

In the second sub-case, the number of internal digits (I) is given by

> where all the variables are marked in the following picture


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -