{"id":22725,"date":"2021-09-27T15:43:09","date_gmt":"2021-09-27T10:13:09","guid":{"rendered":"https:\/\/python-programs.com\/?p=22725"},"modified":"2021-11-22T18:35:38","modified_gmt":"2021-11-22T13:05:38","slug":"python-program-for-section-formula-point-that-divides-a-line-in-given-ratio","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-section-formula-point-that-divides-a-line-in-given-ratio\/","title":{"rendered":"Python Program for Section Formula (Point that Divides a Line in Given Ratio)"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Find the Mid-Point of a Line<\/a>
\nGiven two points of a line and P, Q, the task is to find the point that divides the line in the given ratio P: Q in Python.<\/p>\n

The section formula gives us the coordinates of the point that divides a given line segment into two parts with lengths that are in the ratio m: n.<\/p>\n

Section Formula:<\/strong><\/p>\n

(mx2+nx1)\/(m+n), (my2+ny1)\/(m+n)<\/p><\/blockquote>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given First Point = ( 2, 4 )\r\nGiven Second Point = ( 1, 3 )\r\nGiven ratio value p= 1\r\nGiven ratio value q= 2<\/pre>\n

Output:<\/strong><\/p>\n

The point that divides the line in the given ratio ( 1 : 2 ) is :\r\n( 1.6666666666666667 , 3.6666666666666665 )<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given First Point = ( 5, 7)\r\nGiven Second Point = ( 2, 8 )\r\nGiven ratio value p= 2\r\nGiven ratio value q= 5<\/pre>\n

Output:<\/strong><\/p>\n

The point that divides the line in the given ratio ( 2 : 5 ) is :\r\n( 4.142857142857143 , 7.285714285714286 )<\/pre>\n

Program for Section Formula (Point that Divides a Line in Given Ratio) in Python:<\/h2>\n

Below are the ways to find the point that divides the line in the given ratio P: Q in Python:<\/p>\n