📜  在圆中找到直径的另一端坐标

📅  最后修改于: 2021-05-04 20:43:54             🧑  作者: Mango

给定圆心的中心坐标(c1,c2)和一个坐标(x1,y1),找到直径的另一个端点坐标点(x2,y2)。

例子:

Input  : x1 = –1, y1 = 2, and c1 = 3, c2 = –6
Output : x2 = 7, y2 = -14

Input  : x1 = 6.4, y1 = 3 and c1 = –10.7, c2 = 4
Output : x2 = -27.8, y2 = 5

中点公式:
两端坐标点(x1,y2)和(x2,y2)的中点是点M,可以使用以下公式找到:

 M = \frac{x_{1} + x_{2}}{2}, \  \  \frac{y_{1} + y_{2}}{2}
我们需要一个(x2,y2)坐标,因此我们将中点应用于公式

c1 = ((x1+x2)/2),  c2 = ((y1+y2)/2)
          2*c1 = (x1+x2),  2*c2 = (y1+y2)
          x2 = (2*c1 - x1),  y2 = (2*c2 - y1)
C++
// CPP program to find the 
// other-end point of diameter
#include 
using namespace std;
  
// function to find the
// other-end point of diameter
void endPointOfDiameterofCircle(int x1,
                    int y1, int c1, int c2)
{
    // find end point for x cordinates
    cout << "x2 = " 
            << (float)(2 * c1 - x1)<< "  ";
      
    // find end point for y cordinates
    cout << "y2 = " << (float)(2 * c2 - y1);
      
}
// Driven Program
int main()
{
    int x1 = -4, y1 = -1;
    int c1 = 3, c2 = 5;
      
    endPointOfDiameterofCircle(x1, y1, c1, c2);
      
    return 0;
}


Java
// Java program to find the other-end point of 
// diameter
import java.io.*;
  
class GFG {
      
    // function to find the other-end point of 
    // diameter
    static void endPointOfDiameterofCircle(int x1,
                        int y1, int c1, int c2)
    {
          
        // find end point for x cordinates
        System.out.print( "x2 = "
                            + (2 * c1 - x1) + " ");
          
        // find end point for y cordinates
        System.out.print("y2 = " + (2 * c2 - y1));
    }
      
    // Driven Program
    public static void main (String[] args)
    {
        int x1 = -4, y1 = -1;
        int c1 = 3, c2 = 5;
          
        endPointOfDiameterofCircle(x1, y1, c1, c2);
    }
}
  
// This code is contributed by anuj_67.


Python 3
# Python3 program to find the 
# other-end point of diameter
  
# function to find the
# other-end point of diameter
def endPointOfDiameterofCircle(x1, y1, c1, c2):
  
    # find end point for x cordinates
    print("x2 =", (2 * c1 - x1), end=" ")
      
    # find end point for y cordinates
    print("y2 =" , (2 * c2 - y1))
      
# Driven Program
x1 = -4
y1 = -1
c1 = 3
c2 = 5
      
endPointOfDiameterofCircle(x1, y1, c1, c2)
      
# This code is contributed by Smitha.


C#
// C# program to find the other - 
// end point of diameter
using System;
class GFG {
      
    // function to find the other - end
    // point of  diameter
    static void endPointOfDiameterofCircle(int x1,
                                           int y1,
                                           int c1, 
                                           int c2)
    {
        // find end point for x cordinates
        Console.Write("x2 = "+ (2 * c1 - x1) + " ");
          
        // find end point for y cordinates
        Console.Write("y2 = " + (2 * c2 - y1));
    }
      
    // Driver Code
    public static void Main ()
    {
        int x1 = -4, y1 = -1;
        int c1 = 3, c2 = 5;
          
        endPointOfDiameterofCircle(x1, y1, c1, c2);
    }
}
  
// This code is contributed by anuj_67.


PHP


输出

x2 = 10 y2 = 11

类似地,如果我们给定一个直径的中心(c1,c2)和另一端齿形(x2,y2),我们发现一个(x1,y1)坐标

Proof for (x1, y1) :
          c1 = ((x1+x2)/2),  c2 = ((y1+y2)/2)
          2*c1 = (x1+x2),  2*c2 = (y1+y2)
          x1 = (2*c1 - x2),  y1 = (2*c2 - y2)

因此,直径的另一端坐标(x1,y1)为

x1 = (2*c1 - x2),  y1 = (2*c2 - y2)