- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a line passes through the origin in C++
In this section we will see, how to check a line segment is passes through the origin or not. We have two coordinate points to represent the endpoints of the line segment.
The approach is simple. If we can form the equation of the straight line, and by placing (0, 0) into the equation, and the equation satisfies, then the line passes through the origin.
Suppose the points are and So the equation of line passes through these two lines is −
$$y-y_{1}=\left(\frac{y_{2}-y_{1}}{x_{2}-x_{1}}\right)*\lgroup x-x_{1}\rgroup+c$$
Putting x = 0 and y = 0, we get
$$x_{1}\lgroup y_{2}-y_{1}\rgroup=y_{1}\lgroup x_{2}-x_{1}\rgroup$$
Example
#include<iostream> using namespace std; bool checkPassOrigin(int x1, int y1, int x2, int y2) { return (x1 * (y2 - y1) == y1 * (x2 - x1)); } int main() { if (checkPassOrigin(10, 0, 20, 0) == true) cout << "Passes Through Origin"; else cout << "Not Passing Through Origin"; }
Output
Passes Through Origin
- Related Articles
- How to create a dashed line that passes through Y = 1 in base R?
- How to create a line that passes through specified points in an R plot?
- Check If It Is a Straight Line in C++
- Check if a line touches or intersects a circle in C++
- How heat passes through iron?
- Do electric current passes through the gold?
- If the current through a floodlamp is 5A, what charge passes in 10 seconds? a) 0.5C b) 2C c) 5C d) 50C
- How Light passes through an object?
- By which force, the food passes through the oesophagus?
- Prove that the line segment joining the point of contact of two parallel tangents of a circle passes through its center.
- FabricJS – How to get the coordinates of a Line object as if it has a different origin?
- Fill in the blanks so as to make the following statements true:Given a line and a point, not on the line, there is one and only _____ line which passes through the given point and is _____ to the given line.
- If an incident ray passes through the focus, the reflected ray will(a) pass through the pole (b) be parallel to the principal axis (c) retraces its path (d) pass through the centre of curvature
- Plot the points $(3, 5)$ and $(-1, 3)$ on a graph paper and verify that the straight line passing through these points also passes through the point $(1, 4)$.
- Check if two line segments intersect

Advertisements