- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Three or more points that lie on the same straight line are called collinear points.

And three points lie on the same if the slope of all three pairs of lines formed by them is equal.

Consider, for example, three arbitrary points A, B and C on a 2-D plane, they will be collinear if −

slope of AB = slope of BC = slope of accepts

The slope of a line is generally given by the tangent of the angle it makes with the positive direction of x-axis.

Alternatively, if we have two points that lie on the line, say A(x1, y1) and B(x2, y2), then the slope of line can be calculated by −

Slope of AB = (y2-y1) / (x2-x1)

Let’s write the code for this function −

Following is the code −

const a = {x: 2, y: 4}; const b = {x: 4, y: 6}; const c = {x: 6, y: 8}; const slope = (coor1, coor2) => (coor2.y - coor1.y) / (coor2.x - coor1.x); const areCollinear = (a, b, c) => { return slope(a, b) === slope(b, c) && slope(b, c) === slope(c, a); }; console.log(areCollinear(a, b, c));

Following is the output in the console −

true

- Related Questions & Answers
- Program to check if three points are collinear in C++
- Finding three desired consecutive numbers in JavaScript
- Finding points nearest to origin in JavaScript
- Count of triangles with total n points with m collinear in C++
- Finding three elements with required sum in an array in JavaScript
- Finding distance between two points in a 2-D plane using JavaScript
- Finding top three most occurring words in a string of text in JavaScript
- Check if points are inside ellipse faster than contains_point method (Matplotlib)
- Java Program to Check if two of three Boolean variables are true
- C program to calculate distance between three points in 3D
- C++ Program to Check if a Given Set of Three Points Lie on a Single Line or Not
- Check if three consecutive elements in an array is identical in JavaScript
- Finding tidy numbers - JavaScript
- Finding special array - JavaScript
- Check three consecutive numbers - JavaScript

Advertisements