📜  穿过给定点的直线方程,将其等分为两个相等的线段

📅  最后修改于: 2021-05-30 11:39:10             🧑  作者: Mango

给定一条直线通过给定点(x 0 ,y 0 ) ,以使该点将线段一分为二。任务是找到这条直线的方程式。
例子:

方法:

PQ为直线, AB为轴之间的线段。 x截距和y截距分别为ab
现在,由于C(x 0 ,y 0 )AB对等
x 0 =(a + 0)/ 2,a = 2x 0
类似地, y 0 =(0 + b)/ 2b = 2y 0
我们知道intecept形式的直线方程为

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
 
// Function to print the equation
// of the required line
void line(double x0, double y0)
{
    double c = 2 * y0 * x0;
    cout << y0 << "x"
         << " + " << x0 << "y = " << c;
}
 
// Driver code
int main()
{
    double x0 = 4, y0 = 3;
    line(x0, y0);
 
    return 0;
}


Java
// Java implementation of the approach
class GFG
{
     
// Function to print the equation
// of the required line
static void line(double x0, double y0)
{
    double c = (int)(2 * y0 * x0);
    System.out.println(y0 + "x" + " + " +
                       x0 + "y = " + c);
}
 
// Driver code
public static void main(String[] args)
{
    double x0 = 4, y0 = 3;
    line(x0, y0);
}
}
 
// This code is contributed
// by Code_Mech


Python3
# Python 3 implementation of the approach
 
# Function to print the equation
# of the required line
def line(x0, y0):
    c = 2 * y0 * x0
    print(y0, "x", "+", x0, "y=", c)
 
# Driver code
if __name__ == '__main__':
    x0 = 4
    y0 = 3
    line(x0, y0)
     
# This code is contributed by
# Surendra_Gangwar


C#
// C# implementation of the approach
using System;
 
class GFG
{
     
// Function to print the equation
// of the required line
static void line(double x0, double y0)
{
    double c = (int)(2 * y0 * x0);
    Console.WriteLine(y0 + "x" + " + " +
                    x0 + "y = " + c);
}
 
// Driver code
public static void Main(String[] args)
{
    double x0 = 4, y0 = 3;
    line(x0, y0);
}
}
 
/* This code contributed by PrinciRaj1992 */


PHP


Javascript


输出:
3x + 4y = 24