求圆中直径的另一端坐标

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

null

图片[1]-求圆中直径的另一端坐标-yiteyi-C++库

例如:

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

中点公式: 两端坐标点(x1,y2)和(x2,y2)的中点是点M,可通过以下方法找到: M = frac{x_{1} + x_{2}}{2},   frac{y_{1} + y_{2}}{2}

我们需要a(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 <iostream>
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 coordinates
cout << "x2 = "
<< ( float )(2 * c1 - x1)<< "  " ;
// find end point for y coordinates
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 coordinates
System.out.print( "x2 = "
+ ( 2 * c1 - x1) + " " );
// find end point for y coordinates
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.


Python3

# 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 coordinates
print ( "x2 =" , ( 2 * c1 - x1), end = " " )
# find end point for y coordinates
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 coordinates
Console.Write( "x2 = " + (2 * c1 - x1) + " " );
// find end point for y coordinates
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

<?php
// PHP program to find the
// other-end point of diameter
// function to find the
// other-end point of diameter
function endPointOfDiameterofCircle( $x1 ,
$y1 , $c1 , $c2 )
{
// find end point for x coordinates
echo "x2 = " ,(2 * $c1 - $x1 ), " " ;
// find end point for y coordinates
echo "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
?>


Javascript

<script>
// Javascript program to find the
// other-end point of diameter
// Function to find the
// other-end point of diameter
function endPointOfDiameterofCircle(x1, y1, c1, c2)
{
// Find end point for x coordinates
document.write( "x2 = " + (2 * c1 - x1) + "  " );
// Find end point for y coordinates
document.write( "y2 = " + (2 * c2 - y1));
}
// Driver code
let x1 = -4, y1 = -1;
let c1 = 3, c2 = 5;
endPointOfDiameterofCircle(x1, y1, c1, c2);
// This code is contributed by jana_sayantan
</script>


输出

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)

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享