| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #include "pch.h"
- #include "CS.h"
- #include <math.h>
- CS::CS() {
- }
- CS::~CS()
- {
- }
- // 直角坐标系 -> 球坐标系
- void CS::CartesianToSpherical(CoordCartesian &pcc, CoordSpherical &pcg)
- {
- pcg.r = sqrt(pcc.x*pcc.x + pcc.y*pcc.y + pcc.z*pcc.z);
- pcg.θ = atan2l(pcc.y, pcc.x) * 180 / PI;
- DOUBLE xy2 = pcc.x*pcc.x + pcc.y*pcc.y;
- if (xy2 > 0){
- pcg.φ = atan(pcc.z / sqrt(pcc.x*pcc.x + pcc.y*pcc.y)) * 180 / PI;
- }
- else {
- pcg.φ = 0;
- }
- }
- // 直角坐标系 -> 柱坐标系
- void CS::CartesianToCylindrical(CoordCartesian &pcc, CoordCylindrical &pcy)
- {
- DOUBLE at = atan2l(pcc.y, pcc.x);
- if (at != 0)
- pcy.r = pcc.x / (atan2l(pcc.y, pcc.x) * 180 / PI);
- else
- pcy.r = 0;
- pcy.θ = atan2l(pcc.y , pcc.x) * 180 / PI;
- pcy.z = pcc.z;
- }
- // 点包络值
- DOUBLE CS::EnvelopeValue(DOUBLE x, DOUBLE y)
- {
- return sqrt(x * x + y * y);
- }
|