Checking to see if 3 points are on the same line

前端 未结 5 1242
天涯浪人
天涯浪人 2020-11-30 08:18

I want to know a piece of a code which can actually tell me if 3 points in a 2D space are on the same line or not. A pseudo-code is also sufficient but Python is better.

5条回答
  •  余生分开走
    2020-11-30 09:03

    Read this, and use it to find the equation of a line through the first two points. Follow the instructions to find m and b. Then for your third point, calculate mx + b - y. If the result is zero, the third point is on the same line as the first two.

提交回复
热议问题