C++程式演示直線與點的對偶變換


這是一個C++程式,用於演示直線與點的對偶變換。它包含兩種情況:

情況1:點(a, b)變換為直線(y = ax − b)。

情況2:直線D(y = cx + d)變換為點D’(c, −d)。

函式和虛擬碼

函式 LineTransformation(double c, double d)

Print C: (d / c)
D: (d * -1)

函式 PointTransformation(double x, double y)

Print a = (-1 * y / x)
b = (-1 * y)

示例

#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
void LineTransformation(double c, double d) {
   cout << "C: " << (d / c) << ", D: " << (d * -1);
}
void PointTransformation(double x, double y) {
   cout << "y=" << (-1 * y / x) << "x +" << (-1 * y);
}
int main(int argc, char **argv) {
   cout << "\n1. Line Transformation\n2. Point Transformation";
   int c;
   cin >> c;
   switch (c) {
      case 1:
         cout << "Enter the coefficients of line y=ax-b:";
         double a, b;
         cin >> a >> b;
         LineTransformation(a, b);
         break;
      case 2:
         cout << "Enter the coordinate of point <a, b>";
         double x, y;
         cin >> x >> y;
         PointTransformation(x, y);
         break;
      default:
         break;
   }
}

輸出

1. Line Transformation
2. Point Transformation
1
Enter the coefficients of line y=ax-b:
1
2
C: 2, D: -2

1. Line Transformation
2. Point Transformation
2
Enter the coordinate of point <a, b>
1
2
y=-2x +-2

更新於:2019年7月30日

167 次瀏覽

開啟你的職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.