Find the other-end coordinates of diameter in a circle
Given Centre coordinate (c1, c2) and one coordinate (x1, y1) of the diameter of a circle, find the other end coordinate point (x2, y2) of diameter.
Examples:
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
The Midpoint Formula:
The midpoint of two ends coordinates points, (x1, y2) and (x2, y2) is the point M can be found by using:
We have need of a (x2, y2) coordinates, so we apply the midpoint the formula
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++
#include <iostream>
using namespace std;
void endPointOfDiameterofCircle( int x1,
int y1, int c1, int c2)
{
cout << "x2 = "
<< ( float )(2 * c1 - x1)<< " " ;
cout << "y2 = " << ( float )(2 * c2 - y1);
}
int main()
{
int x1 = -4, y1 = -1;
int c1 = 3, c2 = 5;
endPointOfDiameterofCircle(x1, y1, c1, c2);
return 0;
}
|
Java
import java.io.*;
class GFG {
static void endPointOfDiameterofCircle( int x1,
int y1, int c1, int c2)
{
System.out.print( "x2 = "
+ ( 2 * c1 - x1) + " " );
System.out.print( "y2 = " + ( 2 * c2 - y1));
}
public static void main (String[] args)
{
int x1 = - 4 , y1 = - 1 ;
int c1 = 3 , c2 = 5 ;
endPointOfDiameterofCircle(x1, y1, c1, c2);
}
}
|
Python3
def endPointOfDiameterofCircle(x1, y1, c1, c2):
print ( "x2 =" , ( 2 * c1 - x1), end = " " )
print ( "y2 =" , ( 2 * c2 - y1))
x1 = - 4
y1 = - 1
c1 = 3
c2 = 5
endPointOfDiameterofCircle(x1, y1, c1, c2)
|
C#
using System;
class GFG {
static void endPointOfDiameterofCircle( int x1,
int y1,
int c1,
int c2)
{
Console.Write( "x2 = " + (2 * c1 - x1) + " " );
Console.Write( "y2 = " + (2 * c2 - y1));
}
public static void Main ()
{
int x1 = -4, y1 = -1;
int c1 = 3, c2 = 5;
endPointOfDiameterofCircle(x1, y1, c1, c2);
}
}
|
PHP
<?php
function endPointOfDiameterofCircle( $x1 ,
$y1 , $c1 , $c2 )
{
echo "x2 = " ,(2 * $c1 - $x1 ), " " ;
echo "y2 = " , (2 * $c2 - $y1 );
}
$x1 = -4;
$y1 = -1;
$c1 = 3;
$c2 = 5;
endPointOfDiameterofCircle( $x1 , $y1 ,
$c1 , $c2 );
?>
|
Javascript
<script>
function endPointOfDiameterofCircle(x1, y1, c1, c2)
{
document.write( "x2 = " + (2 * c1 - x1) + " " );
document.write( "y2 = " + (2 * c2 - y1));
}
let x1 = -4, y1 = -1;
let c1 = 3, c2 = 5;
endPointOfDiameterofCircle(x1, y1, c1, c2);
</script>
|
Output
x2 = 10 y2 = 11
Time complexity: O(1)
Auxiliary Space: O(1)
Similarly if we given a centre (c1, c2) and other end coordinate (x2, y2) of a diameter and we finding a (x1, y1) coordinates
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)
So The other end coordinates (x1, y1) of a diameter is
x1 = (2*c1 - x2), y1 = (2*c2 - y2)
Last Updated :
09 Aug, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...