Giả sử có đường cong y = x(A - x), tìm đường pháp tuyến tại điểm (x,y) trên đường cong. A, x, y là số nguyên.
Giải quyết: kiểm tra điểm trên đường cong, tìm đạo hàm: dy/dx = A - 2x. Thay x, y vào dy/dx, tìm pháp tuyến:
Y - y = -(dx/dy)*(X - x)
Ví dụ mã nguồn
#include<iostream> using namespace std; void getNormal(int A, int x, int y) { int differentiation = A - x * 2; if (y == (2 * x - x * x)) { if (differentiation < 0) cout << 0 - differentiation << "y = " << "x" << (0 - x) + (y * differentiation); else if (differentiation > 0) cout << differentiation << "y = " << "-x+" << x + differentiation * y; else cout << "x = " << x; } else cout << "Not possible"; } int main() { int A = 5, x = 2, y = 0; cout << "Equation of normal is: "; getNormal(A, x, y); } Kết quả
Equation of normal is: 1y = -x+2