Given a curve [ y = x(A – x) ], the task is to find normal at given point ( x, y) on that curve, here A is any integer number and x, y also any integer.
Examples:
Input: A = 2, x = 2, y = 0
Output: 2y = x - 2
Since y = x(2 - x)
y = 2x - x^2 differentiate it with respect to x
dy/dx = 2 - 2x put x = 2, y = 0 in this equation
dy/dx = 2 - 2* 2 = -2
equation => (Y - 0 ) = ((-1/-2))*( Y - 2)
=> 2y = x -2
Input: A = 3, x = 4, y = 5
Output: Not possible
Point is not on that curve
Approach: First we need to find given point is on that curve or not if the point is on that curve then:
- We need to differentiate that equation that point don’t think too much for differentiation of this equation if you analyze then you find that dy/dx always become A – 2x.
- Put x, y in dy/dx.
- Equation of normal is Y – y = -(1/( dy/dx )) * (X – x).
Below is the implementation of the above approach:
C++
// C++ program for find curve // at given point #include <bits/stdc++.h> using namespace std; // function for find normal void findNormal(int A, int x, int y) { // differentiate given equation int dif = A - x * 2; // check that point on the curve or not if (y == (2 * x - x * x)) { // if differentiate is negative if (dif < 0) cout << 0 - dif << "y = " << "x" << (0 - x) + (y * dif); else if (dif > 0) // differentiate is positive cout << dif << "y = " << "-x+" << x + dif * y; // differentiate is zero else cout << "x = " << x; } // other wise normal not found else cout << "Not possible"; } // Driver code int main() { // declare variable int A = 2, x = 2, y = 0; // call function findNormal findNormal(A, x, y); return 0; } |
Java
// Java program for find curve // at given point import java.io.*; class GFG { // function for find normal static void findNormal(int A, int x, int y) { // differentiate given equation int dif = A - x * 2; // check that point on the curve or not if (y == (2 * x - x * x)) { // if differentiate is negative if (dif < 0) System.out.print( (0 - dif) + "y = " + "x" +((0 - x) + (y * dif))); else if (dif > 0) // differentiate is positive System.out.print( dif + "y = " + "-x+" + (x + dif * y)); // differentiate is zero else System.out.print( "x = " +x); } // other wise normal not found else System.out.println( "Not possible"); } // Driver code public static void main (String[] args) { // declare variable int A = 2, x = 2, y = 0; // call function findNormal findNormal(A, x, y);; } } // This Code is contributed by inder_verma.. |
Python3
# Python 3 program for find curve # at given point # function for find normal def findNormal(A, x, y): # differentiate given equation dif = A - x * 2 # check that point on the curve or not if (y == (2 * x - x * x)): # if differentiate is negative if (dif < 0): print(0 - dif, "y =", "x", (0 - x) + (y * dif)) elif (dif > 0): # differentiate is positive print(dif, "y =", "- x +", x + dif * y) # differentiate is zero else: print("x =", x) # other wise normal not found else: print("Not possible") # Driver code if __name__ == '__main__': # declare variable A = 2 x = 2 y = 0 # call function findNormal findNormal(A, x, y) # This code is contributed By # Surendra_Gangwar |
C#
// C# program for find curve // at given point using System; class GFG { // function for find normal static void findNormal(int A, int x, int y) { // differentiate given equation int dif = A - x * 2; // check that point on // the curve or not if (y == (2 * x - x * x)) { // if differentiate is negative if (dif < 0) Console.Write((0 - dif) + "y = " + "x" + ((0 - x) + (y * dif))); else if (dif > 0) // differentiate is positive Console.Write(dif + "y = " + "-x + " + (x + dif * y)); // differentiate is zero else Console.Write("x = " + x); } // other wise normal not found else Console.WriteLine("Not possible"); } // Driver code static public void Main () { // declare variable int A = 2, x = 2, y = 0; // call function findNormal findNormal(A, x, y); } } // This code is contributed by ajit |
PHP
<?php // PHP program for find curve // at given point // function for find normal function findNormal($A, $x, $y) { // differentiate given equation $dif = $A - $x * 2; // check that point on the // curve or not if ($y == (2 * $x - $x * $x)) { // if differentiate is negative if ($dif < 0) echo (0 - $dif), "y = ", "x" , (0 - $x) + ($y * $dif); else if ($dif > 0) // differentiate is positive echo $dif , "y = ", "-x+" ,( $x + $dif * $y); // differentiate is zero else echo "x = " , $x; } // other wise normal not found else echo "Not possible"; } // Driver code // declare variable $A = 2; $x = 2; $y = 0; // call function findNormal findNormal($A, $x, $y); // This code is contributed by ajit ?> |
2y = x-2
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Find Tangent at a given point on the curve
- Find nth term of the Dragon Curve Sequence
- Cubic Bezier Curve Implementation in C
- Python - Hilbert Curve using turtle
- Rotation of a point about another point in C++
- Reflection of a point at 180 degree rotation of another point
- Program to find Normal and Trace of a matrix
- Length of the normal from origin on a straight line whose intercepts are given
- Standard Normal Distribution (SND) - Java Program
- Game Theory (Normal form game) | Set 2 (Game with Pure Strategy)
- Game Theory (Normal-form game) | Set 3 (Game with Mixed Strategy)
- Game Theory (Normal-form Game) | Set 4 (Dominance Property-Pure Strategy)
- Game Theory (Normal-form Game) | Set 5 (Dominance Property-Mixed Strategy)
- Game Theory (Normal-form Game) | Set 6 (Graphical Method [2 X N] Game)
- Game Theory (Normal-form Game) | Set 7 (Graphical Method [M X 2] Game)
- Find an Integer point on a line segment with given two ends
- Find the other end point of a line with given one end and mid
- Find middle point segment from given segment lengths
- Find a point that lies inside exactly K given squares
- Find the point on X-axis from given N points having least Sum of Distances from all other points
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

