# line segments from same line showing different angles

Hi,

I am using HoughLinesP to calculate lines from image. But the line segments from same line have different angles.

the segments start and end points and angle (in degrees) and length.

```
id = 0 start(x,y) = (1331 , 790 ) end(x,y) = (1366 , 794 ) Angle = 6.52311 len = 35.2278
id = 2 start(x,y) = (1508 , 807 ) end(x,y) = (1543 , 810 ) Angle = 4.90158 len = 35.1283
id = 4 start(x,y) = (1291 , 786 ) end(x,y) = (1328 , 789 ) Angle = 4.63781 len = 37.1214
id = 8 start(x,y) = (1391 , 795 ) end(x,y) = (1423 , 798 ) Angle = 5.35854 len = 32.1403
id = 9 start(x,y) = (1224 , 779 ) end(x,y) = (1261 , 782 ) Angle = 4.63781 len = 37.1214
```

To calculate angle i used `atan2(y2-y1,x2-x1)*180/3.14`

**I am expecting same angle since the segments are part of same line.**

Is there a way to improve the angle calculation or improving line detection ?

thanks.

i would try fitLine() here.

Or increase the maxLineGap parameter so that you get a single line instead of many segments.

thanks for suggestions, Since i needsegment start and endpoint for furthur calculations increasing maxLineGap is not an option. Also for fitline() i dont know in advance which segments are from sameline.

What do you mean by "same angle"? Your data (looks like a laserscanner) contains errors, so that you will never get exactly the same angles. You have a variance of around 1 degree which is not bad. So what do you expect exactly?

yes this is from laser data , when i use the angle of segment for calculating distance between lines its giving wrong result.

Till you use integer interpretation of lines and you havent same lenght, you cant get exactly same angle. Remember how calculate atan? if dx/dy or dy/dx isnt same you receive diferent angles ((dx +1) / (dy+1) != dx/dy if angle isnt 45 deg)