在 C++ 中查詢二維平面中一個點的映象
在這個問題中,我們給定二維平面中的一個點 P 和方程 ax + by + c = 0 的點 a、b、c。我們的任務是找到二維平面中一個點的映象。
讓我們舉個例子來理解這個問題:
輸入
P = (2, 1), a = 1, b = -1, c = 0
輸出
(1, 2)
解釋
平面看起來像:

解決方案方法
為了解決這個問題,我們需要找到座標為 (x', y') 的點 P'。因此,我們有 R,它是 P - P' 線與映象線相交的中點。
P-R-P' 線垂直於映象。因此,線的方程將是:
ay - by + d = 0
點是 P(x, y);P'(x', y');R(xm, ym)。
點 P 和 R 是已知的。因此,使用這些方程,我們將找到 P' 為:
$$\left(\frac{??'-??}{??}\right)=\left(\frac{??'-??}{??}\right)=\left(\frac{????-????+??}{??^2+x^2}\right)$$
程式演示我們解決方案的工作原理:
示例
#include <iostream>
using namespace std;
void findMirrorImage( double a, double b, double c, double x, double y){
double points = -2 * (a * x + b * y + c) / (a * a + b * b);
double xm = points * a + x;
double ym = points * b + y;
cout<<"("<<xm<<","<<ym<<")";
}
int main(){
double a = -1.0;
double b = 1.0;
double c = 0.0;
double x = 1.0;
double y = 0.0;
cout<<"Image of point ("<<x<<", "<<y<<") using mirror ("<<a<<")x + ("<<b<<")y + ("<<c<< ") = 0, is :";
findMirrorImage(a, b, c, x, y);
return 0;
}輸出
Image of point (1, 0) using mirror (-1)x + (1)y + (0) = 0, is :(0,1)
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP