4#include "../private/h5enum.h"
6#define _USE_MATH_DEFINES
10#include <units/units.hpp>
16Eigen::MatrixX<typename D::Scalar> MdAzIncl2ALL(
17 const Eigen::DenseBase<D> &M,
18 const double& x0,
const double& y0,
const double& kb,
19 const std::string& angularUnitsFrom,
20 const std::string& angularUnitsTo,
24Eigen::MatrixX<typename D::Scalar> TvdXY2ALL(
25 const Eigen::DenseBase<D> &M,
26 const double& x0,
const double& y0,
const double& kb,
27 const std::string& angularUnits,
31Eigen::MatrixX<typename D::Scalar> TvdDxDy2ALL(
32 const Eigen::DenseBase<D> &M,
33 const double& x0,
const double& y0,
const double& kb,
34 const std::string& angularUnits,
38Eigen::MatrixX<typename D::Scalar> TvdssXY2ALL(
39 const Eigen::DenseBase<D> &M,
40 const double& x0,
const double& y0,
const double& kb,
41 const std::string& angularUnits,
45Eigen::MatrixX<typename D::Scalar> TvdssDxDy2ALL(
46 const Eigen::DenseBase<D> &M,
47 const double& x0,
const double& y0,
const double& kb,
48 const std::string& angularUnits,
52Eigen::MatrixX<typename D::Scalar> traj2ALL(
53 const Eigen::DenseBase<D> &M,
54 const double& x0,
const double& y0,
const double& kb,
55 const std::string& angularUnitsFrom,
56 const std::string& angularUnitsTo,
57 const h5geo::TrajectoryFormat& trajFormat,
62Eigen::MatrixX<typename D::Scalar> MdAzIncl2MdXYTvd(
63 const Eigen::DenseBase<D> &M,
64 const double& x0,
const double& y0,
65 const std::string& angularUnits,
69Eigen::MatrixX<typename D::Scalar> TvdXY2MdXYTvd(
70 const Eigen::DenseBase<D> &M,
71 const double& x0,
const double& y0,
75Eigen::MatrixX<typename D::Scalar> TvdDxDy2MdXYTvd(
76 const Eigen::DenseBase<D> &M,
77 const double& x0,
const double& y0,
81Eigen::MatrixX<typename D::Scalar> TvdssXY2MdXYTvd(
82 const Eigen::DenseBase<D> &M,
83 const double& x0,
const double& y0,
const double& kb,
87Eigen::MatrixX<typename D::Scalar> TvdssDxDy2MdXYTvd(
88 const Eigen::DenseBase<D> &M,
89 const double& x0,
const double& y0,
const double& kb,
93Eigen::MatrixX<typename D::Scalar> TvdXY2MdAzIncl(
94 const Eigen::DenseBase<D> &M,
95 const double& x0,
const double& y0,
const std::string& angularUnits,
const bool& XNorth);
98Eigen::MatrixX<typename D::Scalar> TvdDxDy2MdAzIncl(
99 const Eigen::DenseBase<D> &M,
const std::string& angularUnits,
const bool& XNorth);
102Eigen::MatrixX<typename D::Scalar> TvdssXY2MdAzIncl(
103 const Eigen::DenseBase<D> &M,
104 const double& x0,
const double& y0,
const double& kb,
const std::string& angularUnits,
const bool& XNorth);
107Eigen::MatrixX<typename D::Scalar> TvdssDxDy2MdAzIncl(
108 const Eigen::DenseBase<D> &M,
109 const double& kb,
const std::string& angularUnits,
const bool& XNorth);
119 const double& arcLen,
120 const double& chordLen,
122 const size_t& max_iter);
125inline double _betaAngle(
130 const std::string& angularUnits)
132 if (!angularUnits.empty()){
133 double coef = units::convert(
134 units::unit_from_string(angularUnits),
135 units::unit_from_string(
"radian"));
142 return acos(cos(I2-I1) - (sin(I1)*sin(I2)*(1 - cos(A2-A1))));
146inline double _ratioFactor(
double B,
const std::string& angularUnits)
148 if (!angularUnits.empty()){
149 double coef = units::convert(
150 units::unit_from_string(angularUnits),
151 units::unit_from_string(
"radian"));
156 return 1 + pow(B,2)/12 + pow(B,4)/120 + pow(B,6)/20160;
158 return 2 / B * tan(B / 2);
162inline double _deltaEast(
169 const std::string& angularUnits)
171 if (!angularUnits.empty()){
172 double coef = units::convert(
173 units::unit_from_string(angularUnits),
174 units::unit_from_string(
"radian"));
181 return dMD/2 * (sin(I1)*sin(A1) + sin(I2)*sin(A2))*RF;
185inline double _deltaNorth(
192 const std::string& angularUnits)
194 if (!angularUnits.empty()){
195 double coef = units::convert(
196 units::unit_from_string(angularUnits),
197 units::unit_from_string(
"radian"));
204 return dMD/2 * (sin(I1)*cos(A1) + sin(I2)*cos(A2))*RF;
208inline double _deltaZ(
213 const std::string& angularUnits)
215 if (!angularUnits.empty()){
216 double coef = units::convert(
217 units::unit_from_string(angularUnits),
218 units::unit_from_string(
"radian"));
223 return dMD/2 * (cos(I1) + cos(I2))*RF;
227inline double _dMDFromDeltaEast(
234 const std::string& angularUnits)
236 if (!angularUnits.empty()){
237 double coef = units::convert(
238 units::unit_from_string(angularUnits),
239 units::unit_from_string(
"radian"));
246 return 2*dE / ((sin(I1)*sin(A1) + sin(I2)*sin(A2))*RF);
250inline double _dMDFromDeltaNorth(
257 const std::string& angularUnits)
259 if (!angularUnits.empty()){
260 double coef = units::convert(
261 units::unit_from_string(angularUnits),
262 units::unit_from_string(
"radian"));
269 return 2*dN / ((sin(I1)*cos(A1) + sin(I2)*cos(A2))*RF);
273inline double _dMDFromDeltaZ(
278 const std::string& angularUnits)
280 if (!angularUnits.empty()){
281 double coef = units::convert(
282 units::unit_from_string(angularUnits),
283 units::unit_from_string(
"radian"));
288 return 2*dZ / ((cos(I1) + cos(I2))*RF);
296 const std::string& angularUnits)
298 if (!angularUnits.empty()){
299 double coef = units::convert(
300 units::unit_from_string(angularUnits),
301 units::unit_from_string(
"radian"));
305 return chord*a-2*arc*sin(a/2);
313 const std::string& angularUnits)
315 if (!angularUnits.empty()){
316 double coef = units::convert(
317 units::unit_from_string(angularUnits),
318 units::unit_from_string(
"radian"));
322 return chord-arc*cos(a/2);
329 const std::string& angularUnits)
331 if (!angularUnits.empty()){
332 double coef = units::convert(
333 units::unit_from_string(angularUnits),
334 units::unit_from_string(
"radian"));
338 return arc*sin(a/2)/2;
348Eigen::MatrixX<typename D::Scalar> h5geo::MdAzIncl2ALL(
349 const Eigen::DenseBase<D> &M,
350 const double& x0,
const double& y0,
const double& kb,
351 const std::string& angularUnitsFrom,
352 const std::string& angularUnitsTo,
356 return Eigen::MatrixX<typename D::Scalar>();
358 Eigen::MatrixX<typename D::Scalar> M_MdXYTvd =
359 MdAzIncl2MdXYTvd(M, x0, y0, angularUnitsFrom, XNorth);
361 Eigen::MatrixX<typename D::Scalar> M_OUT(M.rows(), 9);
362 M_OUT.col(0) = M_MdXYTvd.col(0);
363 M_OUT.col(1) = M_MdXYTvd.col(1);
364 M_OUT.col(2) = M_MdXYTvd.col(2);
365 M_OUT.col(3) = M_MdXYTvd.col(3).array() - kb;
366 M_OUT.col(4) = M_MdXYTvd.col(3);
367 M_OUT.col(5) = M_MdXYTvd.col(1).array() - x0;
368 M_OUT.col(6) = M_MdXYTvd.col(2).array() - y0;
370 if (!angularUnitsTo.empty()){
371 double coef = units::convert(
372 units::unit_from_string(angularUnitsFrom),
373 units::unit_from_string(angularUnitsTo));
374 M_OUT.col(7) = M.col(1)*coef;
375 M_OUT.col(8) = M.col(2)*coef;
377 M_OUT.col(7) = M.col(1);
378 M_OUT.col(8) = M.col(2);
385Eigen::MatrixX<typename D::Scalar> h5geo::TvdXY2ALL(
386 const Eigen::DenseBase<D> &M,
387 const double& x0,
const double& y0,
const double& kb,
388 const std::string& angularUnits,
392 return Eigen::MatrixX<typename D::Scalar>();
394 Eigen::MatrixX<typename D::Scalar> M_MdAzIncl =
395 TvdXY2MdAzIncl(M, x0, y0, angularUnits, XNorth);
397 Eigen::MatrixX<typename D::Scalar> M_OUT(M.rows(), 9);
398 M_OUT.col(0) = M_MdAzIncl.col(0);
399 M_OUT.col(1) = M.col(1);
400 M_OUT.col(2) = M.col(2);
401 M_OUT.col(3) = M.col(0).array() - kb;
402 M_OUT.col(4) = M.col(0);
403 M_OUT.col(5) = M.col(1).array() - x0;
404 M_OUT.col(6) = M.col(2).array() - y0;
405 M_OUT.col(7) = M_MdAzIncl.col(1);
406 M_OUT.col(8) = M_MdAzIncl.col(2);
411Eigen::MatrixX<typename D::Scalar> h5geo::TvdDxDy2ALL(
412 const Eigen::DenseBase<D> &M,
413 const double& x0,
const double& y0,
const double& kb,
414 const std::string& angularUnits,
418 return Eigen::MatrixX<typename D::Scalar>();
420 Eigen::MatrixX<typename D::Scalar> M_MdAzIncl =
421 TvdDxDy2MdAzIncl(M, angularUnits, XNorth);
423 Eigen::MatrixX<typename D::Scalar> M_OUT(M.rows(), 9);
424 M_OUT.col(0) = M_MdAzIncl.col(0);
425 M_OUT.col(1) = M.col(1).array() + x0;
426 M_OUT.col(2) = M.col(2).array() + y0;
427 M_OUT.col(3) = M.col(0).array() - kb;
428 M_OUT.col(4) = M.col(0);
429 M_OUT.col(5) = M.col(1);
430 M_OUT.col(6) = M.col(2);
431 M_OUT.col(7) = M_MdAzIncl.col(1);
432 M_OUT.col(8) = M_MdAzIncl.col(2);
437Eigen::MatrixX<typename D::Scalar> h5geo::TvdssXY2ALL(
438 const Eigen::DenseBase<D> &M,
439 const double& x0,
const double& y0,
const double& kb,
440 const std::string& angularUnits,
444 return Eigen::MatrixX<typename D::Scalar>();
446 Eigen::MatrixX<typename D::Scalar> M_MdAzIncl =
447 TvdssXY2MdAzIncl(M, x0, y0, kb, angularUnits, XNorth);
449 Eigen::MatrixX<typename D::Scalar> M_OUT(M.rows(), 9);
450 M_OUT.col(0) = M_MdAzIncl.col(0);
451 M_OUT.col(1) = M.col(1);
452 M_OUT.col(2) = M.col(2);
453 M_OUT.col(3) = M.col(0);
454 M_OUT.col(4) = M.col(0).array() + kb;
455 M_OUT.col(5) = M.col(1).array() - x0;
456 M_OUT.col(6) = M.col(2).array() - y0;
457 M_OUT.col(7) = M_MdAzIncl.col(1);
458 M_OUT.col(8) = M_MdAzIncl.col(2);
463Eigen::MatrixX<typename D::Scalar> h5geo::TvdssDxDy2ALL(
464 const Eigen::DenseBase<D> &M,
465 const double& x0,
const double& y0,
const double& kb,
466 const std::string& angularUnits,
470 return Eigen::MatrixX<typename D::Scalar>();
472 Eigen::MatrixX<typename D::Scalar> M_MdAzIncl =
473 TvdssDxDy2MdAzIncl(M, kb, angularUnits, XNorth);
475 Eigen::MatrixX<typename D::Scalar> M_OUT(M.rows(), 9);
476 M_OUT.col(0) = M_MdAzIncl.col(0);
477 M_OUT.col(1) = M.col(1).array() + x0;
478 M_OUT.col(2) = M.col(2).array() + y0;
479 M_OUT.col(3) = M.col(0);
480 M_OUT.col(4) = M.col(0).array() + kb;
481 M_OUT.col(5) = M.col(1);
482 M_OUT.col(6) = M.col(2);
483 M_OUT.col(7) = M_MdAzIncl.col(1);
484 M_OUT.col(8) = M_MdAzIncl.col(2);
489Eigen::MatrixX<typename D::Scalar> h5geo::traj2ALL(
490 const Eigen::DenseBase<D> &M,
491 const double& x0,
const double& y0,
const double& kb,
492 const std::string& angularUnitsFrom,
493 const std::string& angularUnitsTo,
494 const h5geo::TrajectoryFormat& trajFormat,
497 switch (trajFormat) {
498 case h5geo::TrajectoryFormat::MD_AZIM_INCL:
499 return h5geo::MdAzIncl2ALL(M, x0, y0, kb, angularUnitsFrom, angularUnitsTo, XNorth);
500 case h5geo::TrajectoryFormat::TVDSS_DX_DY:
501 return h5geo::TvdssDxDy2ALL(M, x0, y0, kb, angularUnitsTo, XNorth);
502 case h5geo::TrajectoryFormat::TVDSS_X_Y:
503 return h5geo::TvdssXY2ALL(M, x0, y0, kb, angularUnitsTo, XNorth);
504 case h5geo::TrajectoryFormat::TVD_DX_DY:
505 return h5geo::TvdDxDy2ALL(M, x0, y0, kb, angularUnitsTo, XNorth);
506 case h5geo::TrajectoryFormat::TVD_X_Y:
507 return h5geo::TvdXY2ALL(M, x0, y0, kb, angularUnitsTo, XNorth);
509 return Eigen::MatrixX<typename D::Scalar>();
514Eigen::MatrixX<typename D::Scalar> h5geo::MdAzIncl2MdXYTvd(
515 const Eigen::DenseBase<D> &M,
516 const double& x0,
const double& y0,
517 const std::string& angularUnits,
521 return Eigen::MatrixX<typename D::Scalar>();
524 if (!angularUnits.empty()){
525 coef = units::convert(
526 units::unit_from_string(angularUnits),
527 units::unit_from_string(
"radian"));
530 Eigen::MatrixX<typename D::Scalar> M_OUT(M.rows(), 4);
531 M_OUT.col(0) = M.col(0);
532 typename D::Scalar I1, I2, A1, A2, dMD, B, RF, dx, dy, dz;
534 for (
size_t i = 0; i < M.rows(); i++){
543 A2 = M(i-1, 1) * coef;
545 I2 = M(i-1, 2) * coef;
546 dMD = M(i, 0) - M(i-1, 0);
549 B = _betaAngle(I1, I2, A1, A2,
"");
550 RF = _ratioFactor(B,
"");
553 dx = _deltaNorth(dMD, I1, I2, A1, A2, RF,
"");
554 dy = _deltaEast(dMD, I1, I2, A1, A2, RF,
"");
556 dx = _deltaEast(dMD, I1, I2, A1, A2, RF,
"");
557 dy = _deltaNorth(dMD, I1, I2, A1, A2, RF,
"");
560 dz = _deltaZ(dMD, I1, I2, RF,
"");
563 M_OUT(0, 1) = x0 + dx;
564 M_OUT(0, 2) = y0 + dy;
567 M_OUT(i, 1) = M_OUT(i-1, 1) + dx;
568 M_OUT(i, 2) = M_OUT(i-1, 2) + dy;
569 M_OUT(i, 3) = M_OUT(i-1, 3) + dz;
576Eigen::MatrixX<typename D::Scalar> h5geo::TvdXY2MdXYTvd(
577 const Eigen::DenseBase<D> &M,
578 const double& x0,
const double& y0,
582 return Eigen::MatrixX<typename D::Scalar>();
584 Eigen::MatrixX<typename D::Scalar> M_MdAzIncl =
585 TvdXY2MdAzIncl(M, x0, y0,
"", XNorth);
587 Eigen::MatrixX<typename D::Scalar> M_MdXYTvd(M.rows(), 4);
589 M_MdXYTvd.col(0) = M_MdAzIncl.col(0);
590 M_MdXYTvd.col(1) = M.col(1);
591 M_MdXYTvd.col(2) = M.col(2);
592 M_MdXYTvd.col(3) = M.col(0);
598Eigen::MatrixX<typename D::Scalar> h5geo::TvdDxDy2MdXYTvd(
599 const Eigen::DenseBase<D> &M,
600 const double& x0,
const double& y0,
604 return Eigen::MatrixX<typename D::Scalar>();
606 Eigen::MatrixX<typename D::Scalar> M_MdAzIncl =
607 TvdDxDy2MdAzIncl(M,
"", XNorth);
609 Eigen::MatrixX<typename D::Scalar> M_MdXYTvd(M.rows(), 4);
611 M_MdXYTvd.col(0) = M_MdAzIncl.col(0);
612 M_MdXYTvd.col(1) = M.col(1).array() + x0;
613 M_MdXYTvd.col(2) = M.col(2).array() + y0;
614 M_MdXYTvd.col(3) = M.col(0);
620Eigen::MatrixX<typename D::Scalar> h5geo::TvdssXY2MdXYTvd(
621 const Eigen::DenseBase<D> &M,
622 const double& x0,
const double& y0,
const double& kb,
626 return Eigen::MatrixX<typename D::Scalar>();
628 Eigen::MatrixX<typename D::Scalar> M_MdAzIncl =
629 TvdssXY2MdAzIncl(M, x0, y0, kb,
"", XNorth);
631 Eigen::MatrixX<typename D::Scalar> M_MdXYTvd(M.rows(), 4);
633 M_MdXYTvd.col(0) = M_MdAzIncl.col(0);
634 M_MdXYTvd.col(1) = M.col(1);
635 M_MdXYTvd.col(2) = M.col(2);
636 M_MdXYTvd.col(3) = M.col(0).array() + kb;
642Eigen::MatrixX<typename D::Scalar> h5geo::TvdssDxDy2MdXYTvd(
643 const Eigen::DenseBase<D> &M,
644 const double& x0,
const double& y0,
const double& kb,
648 return Eigen::MatrixX<typename D::Scalar>();
650 Eigen::MatrixX<typename D::Scalar> M_MdAzIncl =
651 TvdssDxDy2MdAzIncl(M, kb,
"", XNorth);
653 Eigen::MatrixX<typename D::Scalar> M_MdXYTvd(M.rows(), 4);
655 M_MdXYTvd.col(0) = M_MdAzIncl.col(0);
656 M_MdXYTvd.col(1) = M.col(1).array() + x0;
657 M_MdXYTvd.col(2) = M.col(2).array() + y0;
658 M_MdXYTvd.col(3) = M.col(0).array() + kb;
664Eigen::MatrixX<typename D::Scalar> h5geo::TvdXY2MdAzIncl(
665 const Eigen::DenseBase<D> &M,
666 const double& x0,
const double& y0,
667 const std::string& angularUnits,
671 return Eigen::MatrixX<typename D::Scalar>();
673 Eigen::MatrixX<typename D::Scalar> MM = M;
674 MM.col(1) = MM.col(1).array() - x0;
675 MM.col(2) = MM.col(2).array() - y0;
677 return TvdDxDy2MdAzIncl(MM, angularUnits, XNorth);
681Eigen::MatrixX<typename D::Scalar> h5geo::TvdDxDy2MdAzIncl(
682 const Eigen::DenseBase<D> &M,
const std::string& angularUnits,
const bool& XNorth)
685 return Eigen::MatrixX<typename D::Scalar>();
687 Eigen::MatrixX<typename D::Scalar> M_OUT(M.rows(), 3);
688 typename D::Scalar I1, I2, A1, A2, dMD, B, RF, dx, dy, dz;
690 for (
size_t i = 0; i < M.rows(); i++){
703 I1 = atan2(sqrt(pow(dx,2)+pow(dy,2)), dz);
706 dx = M(i, 1) - M(i-1, 1);
707 dy = M(i, 2) - M(i-1, 2);
708 dz = M(i, 0) - M(i-1, 0);
718 I2 = atan2(sqrt(pow(dx,2)+pow(dy,2)), dz);
721 B = _betaAngle(I1, I2, A1, A2,
"");
722 RF = _ratioFactor(B,
"");
724 dMD = _dMDFromDeltaZ(dz, I1, I2, RF,
"");
729 M_OUT(i, 0) = M_OUT(i-1, 0) + dMD;
735 if (!angularUnits.empty()){
736 double coef = units::convert(
737 units::unit_from_string(
"radian"),
738 units::unit_from_string(angularUnits));
739 M_OUT.col(1) = M_OUT.col(1).array() * coef;
740 M_OUT.col(2) = M_OUT.col(2).array() * coef;
747Eigen::MatrixX<typename D::Scalar> h5geo::TvdssXY2MdAzIncl(
748 const Eigen::DenseBase<D> &M,
749 const double& x0,
const double& y0,
const double& kb,
750 const std::string& angularUnits,
754 return Eigen::MatrixX<typename D::Scalar>();
756 Eigen::MatrixX<typename D::Scalar> MM = M;
757 MM.col(0) = MM.col(0).array() + kb;
758 MM.col(1) = MM.col(1).array() - x0;
759 MM.col(2) = MM.col(2).array() - y0;
761 return TvdDxDy2MdAzIncl(MM, angularUnits, XNorth);
765Eigen::MatrixX<typename D::Scalar> h5geo::TvdssDxDy2MdAzIncl(
766 const Eigen::DenseBase<D> &M,
767 const double& kb,
const std::string& angularUnits,
const bool& XNorth)
770 return Eigen::MatrixX<typename D::Scalar>();
772 Eigen::MatrixX<typename D::Scalar> MM = M;
773 MM.col(0) = MM.col(0).array() + kb;
775 return TvdDxDy2MdAzIncl(MM, angularUnits, XNorth);
780 const double& arcLen,
781 const double& chordLen,
783 const size_t& max_iter)
785 if (arcLen <= chordLen ||
788 return Eigen::VectorX<double>();
791 double a_max = 2*M_PI;
792 double a0, a1, f, df, ddf;
793 for (a0 = a_min; a0 < a_max; a0 = a0+0.1){
794 f = _fa(arcLen, chordLen, a0,
"");
795 ddf = _ddfa(arcLen, a0,
"");
800 df = _dfa(arcLen, chordLen, a0,
"");
802 return Eigen::VectorX<double>();
805 size_t i = 1, ii = 0;
806 while (abs(f) > eps && i < max_iter){
807 f = _fa(arcLen, chordLen, a0,
"");
808 df = _dfa(arcLen, chordLen, a0,
"");
810 return Eigen::VectorX<double>();
814 if (a1 < a_min || a1 > a_max){
815 while (a1 < a_min || a1 > a_max){
819 return Eigen::VectorX<double>();
825 double radius = arcLen/a1;
827 Eigen::Vector2<double> v;
Basic namespace.
Definition h5base.h:29
Eigen::VectorX< double > angleAndRadius(const double &arcLen, const double &chordLen, const double &eps, const size_t &max_iter)
angleAndRadius Calculate angle and radius from arc and chord
Definition h5deviation.h:779