用 C++ 求曲线上给定点的法线
假设我们有一条曲线,如 y = x(A - x);我们需要找到该曲线上给定点 (x,y) 处的法线。此处,A 是一个整数,x 和 y 也是整数。
要解决此问题,我们需要检查给定点是否在曲线上;如果在,则求该曲线的导数,即为:
$$\frac{\text{d}y}{\text{d}x}=A-2x$$
然后将 x 和 y 代入 dy/dx,再使用以下公式求法线:$$Y-y=-\lgroup\frac{\text{d}x}{\text{d}y}\rgroup*\lgroup X-x \rgroup$$
示例
#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);
}输出
Equation of normal is: 1y = -x+2
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP