📜  垂直于线的坡度

📅  最后修改于: 2021-04-23 22:18:04             🧑  作者: Mango

给定一条线的斜率(m 1 ),并且必须找到另一条与给定线垂直的斜率。

例子:

Input : 5
Output : Slope of perpendicular line is : -0.20

Input : 4
Output : Slope of perpendicular line is : -0.25

假设我们得到了两个垂直线段AB和CD。 AB的斜率为m 1 ,线CD为m 2

以上公式如何运作?
令线AB的斜率为m1,我们需要找到线CD的斜率。下图给出了有关公式工作的想法。

C++
// C++ program find slope of perpendicular line
#include 
using namespace std;
  
// Function to find
// the Slope of other line
double findPCSlope(double m)
{
    return -1.0 / m;
}
  
int main()
{
    double m = 2.0;
    cout << findPCSlope(m);
    return 0;
}


Java
// Java program to illustrate ...
  
import java.io.*;
import java.util.*;
  
class GFG {
  
    // Function to find
    // the Slope of other line
    static double findPCSlope(double m)
    {
        return -1.0 / m;
    }
  
    public static void main(String[] args)
    {
  
        double m = 2.0;
        System.out.println(findPCSlope(m));
    }
}


Python 3
# Python 3 program find 
# slope of perpendicular line
  
# Function to find
# the Slope of other line
def findPCSlope(m):
  
    return -1.0 / m
  
m = 2.0
print(findPCSlope(m))
  
# This code is contributed
# by Smitha


C#
// C# Program to find Slope 
// of perpendicular to line
using System;
  
class GFG {
  
    // Function to find
    // the Slope of other line
    static double findPCSlope(double m)
    {
        return -1.0 / m;
    }
  
    // Driver Code
    public static void Main()
    {
  
        double m = 2.0;
        Console.Write(findPCSlope(m));
    }
}
  
// This code is contributed by nitin mittal


PHP


输出:
-0.5