Skip to content

Instantly share code, notes, and snippets.

@pn11
Last active Aug 29, 2015
Embed
What would you like to do?
緯度、経度からモルワイデ図法での座標を出すプログラムをクラスの勉強をしながらつくった。定義はWikipediaに従う。テータはニュートン法で求める。 http://ja.wikipedia.org/wiki/%E3%83%A2%E3%83%AB%E3%83%AF%E3%82%A4%E3%83%87%E5%9B%B3%E6%B3%95
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
using namespace std;
class ConvertMollweide
{
private:
double fLong, fLat, fTheta, fX, fY;
public:
void SetLong(double longtitude);
void SetLat(double latitude);
void SetLongLat(double longtitude, double latitude);
double GetLong();
double GetLat();
void CalcTheta();
double GetX();
double GetY();
};
void ConvertMollweide::SetLong(double longtitude){
fLong = longtitude;
}
void ConvertMollweide::SetLat(double latitude){
fLat = latitude;
}
void ConvertMollweide::SetLongLat(double longtitude, double latitude){
fLong = longtitude;
fLat = latitude;
}
void ConvertMollweide::CalcTheta(){
// Set 2x = theta and calculate x to save time
double x = 0, dx;
int i =0;
while (1){
dx = -( x + sin(x) - M_PI*sin(fLat) ) / ( cos(x) + 1 );
x += dx;
i++;
if ( fabs(dx) <= 0.00001 )
break;
}
fTheta = x / 2.0;
}
double ConvertMollweide::GetLong(){
return fLong;
}
double ConvertMollweide::GetLat(){
return fLat;
}
double ConvertMollweide::GetX(){
fX = fLong * cos(fTheta);
return fX;
}
double ConvertMollweide::GetY(){
fY = M_PI / 2.0 * sin(fTheta);
return fY;
}
int main(){
ConvertMollweide cm;
for (int i = 0; i < 36; i++){
double phi = (double(i)*10.0 - 180.0) /360.0 * M_PI;
for (int j = 0; j < 18; j++){
double theta = (double(j)*10.0 - 90.0) / 360.0 * M_PI;
cm.SetLongLat(theta, phi);
cm.CalcTheta();
cout << cm.GetX() << " " << cm.GetY() << endl;
}
}
}
-7.06188e-06 -1.5708
-6.27722e-06 -1.5708
-5.49257e-06 -1.5708
-4.70792e-06 -1.5708
-3.92327e-06 -1.5708
-3.13861e-06 -1.5708
-2.35396e-06 -1.5708
-1.56931e-06 -1.5708
-7.84653e-07 -1.5708
0 -1.5708
7.84653e-07 -1.5708
1.56931e-06 -1.5708
2.35396e-06 -1.5708
3.13861e-06 -1.5708
3.92327e-06 -1.5708
4.70792e-06 -1.5708
5.49257e-06 -1.5708
6.27722e-06 -1.5708
-0.162455 -1.53683
-0.144405 -1.53683
-0.126354 -1.53683
-0.108304 -1.53683
-0.0902529 -1.53683
-0.0722023 -1.53683
-0.0541518 -1.53683
-0.0361012 -1.53683
-0.0180506 -1.53683
0 -1.53683
0.0180506 -1.53683
0.0361012 -1.53683
0.0541518 -1.53683
0.0722023 -1.53683
0.0902529 -1.53683
0.108304 -1.53683
0.126354 -1.53683
0.144405 -1.53683
-0.255988 -1.48502
-0.227545 -1.48502
-0.199102 -1.48502
-0.170659 -1.48502
-0.142216 -1.48502
-0.113772 -1.48502
-0.0853293 -1.48502
-0.0568862 -1.48502
-0.0284431 -1.48502
0 -1.48502
0.0284431 -1.48502
0.0568862 -1.48502
0.0853293 -1.48502
0.113772 -1.48502
0.142216 -1.48502
0.170659 -1.48502
0.199102 -1.48502
0.227545 -1.48502
-0.332348 -1.42323
-0.295421 -1.42323
-0.258493 -1.42323
-0.221566 -1.42323
-0.184638 -1.42323
-0.14771 -1.42323
-0.110783 -1.42323
-0.0738552 -1.42323
-0.0369276 -1.42323
0 -1.42323
0.0369276 -1.42323
0.0738552 -1.42323
0.110783 -1.42323
0.14771 -1.42323
0.184638 -1.42323
0.221566 -1.42323
0.258493 -1.42323
0.295421 -1.42323
-0.398245 -1.35389
-0.353996 -1.35389
-0.309746 -1.35389
-0.265497 -1.35389
-0.221247 -1.35389
-0.176998 -1.35389
-0.132748 -1.35389
-0.0884989 -1.35389
-0.0442494 -1.35389
0 -1.35389
0.0442494 -1.35389
0.0884989 -1.35389
0.132748 -1.35389
0.176998 -1.35389
0.221247 -1.35389
0.265497 -1.35389
0.309746 -1.35389
0.353996 -1.35389
-0.456404 -1.27835
-0.405692 -1.27835
-0.354981 -1.27835
-0.304269 -1.27835
-0.253558 -1.27835
-0.202846 -1.27835
-0.152135 -1.27835
-0.101423 -1.27835
-0.0507115 -1.27835
0 -1.27835
0.0507115 -1.27835
0.101423 -1.27835
0.152135 -1.27835
0.202846 -1.27835
0.253558 -1.27835
0.304269 -1.27835
0.354981 -1.27835
0.405692 -1.27835
-0.508249 -1.19755
-0.451777 -1.19755
-0.395305 -1.19755
-0.338833 -1.19755
-0.28236 -1.19755
-0.225888 -1.19755
-0.169416 -1.19755
-0.112944 -1.19755
-0.0564721 -1.19755
0 -1.19755
0.0564721 -1.19755
0.112944 -1.19755
0.169416 -1.19755
0.225888 -1.19755
0.28236 -1.19755
0.338833 -1.19755
0.395305 -1.19755
0.451777 -1.19755
-0.554624 -1.11219
-0.492999 -1.11219
-0.431374 -1.11219
-0.369749 -1.11219
-0.308125 -1.11219
-0.2465 -1.11219
-0.184875 -1.11219
-0.12325 -1.11219
-0.0616249 -1.11219
0 -1.11219
0.0616249 -1.11219
0.12325 -1.11219
0.184875 -1.11219
0.2465 -1.11219
0.308125 -1.11219
0.369749 -1.11219
0.431374 -1.11219
0.492999 -1.11219
-0.596072 -1.02284
-0.529842 -1.02284
-0.463612 -1.02284
-0.397381 -1.02284
-0.331151 -1.02284
-0.264921 -1.02284
-0.198691 -1.02284
-0.13246 -1.02284
-0.0662302 -1.02284
0 -1.02284
0.0662302 -1.02284
0.13246 -1.02284
0.198691 -1.02284
0.264921 -1.02284
0.331151 -1.02284
0.397381 -1.02284
0.463612 -1.02284
0.529842 -1.02284
-0.632958 -0.929977
-0.562629 -0.929977
-0.492301 -0.929977
-0.421972 -0.929977
-0.351643 -0.929977
-0.281315 -0.929977
-0.210986 -0.929977
-0.140657 -0.929977
-0.0703287 -0.929977
0 -0.929977
0.0703287 -0.929977
0.140657 -0.929977
0.210986 -0.929977
0.281315 -0.929977
0.351643 -0.929977
0.421972 -0.929977
0.492301 -0.929977
0.562629 -0.929977
-0.665538 -0.83405
-0.591589 -0.83405
-0.51764 -0.83405
-0.443692 -0.83405
-0.369743 -0.83405
-0.295795 -0.83405
-0.221846 -0.83405
-0.147897 -0.83405
-0.0739486 -0.83405
0 -0.83405
0.0739486 -0.83405
0.147897 -0.83405
0.221846 -0.83405
0.295795 -0.83405
0.369743 -0.83405
0.443692 -0.83405
0.51764 -0.83405
0.591589 -0.83405
-0.693994 -0.735453
-0.616883 -0.735453
-0.539773 -0.735453
-0.462663 -0.735453
-0.385552 -0.735453
-0.308442 -0.735453
-0.231331 -0.735453
-0.154221 -0.735453
-0.0771104 -0.735453
0 -0.735453
0.0771104 -0.735453
0.154221 -0.735453
0.231331 -0.735453
0.308442 -0.735453
0.385552 -0.735453
0.462663 -0.735453
0.539773 -0.735453
0.616883 -0.735453
-0.718459 -0.634559
-0.638631 -0.634559
-0.558802 -0.634559
-0.478973 -0.634559
-0.399144 -0.634559
-0.319315 -0.634559
-0.239486 -0.634559
-0.159658 -0.634559
-0.0798288 -0.634559
0 -0.634559
0.0798288 -0.634559
0.159658 -0.634559
0.239486 -0.634559
0.319315 -0.634559
0.399144 -0.634559
0.478973 -0.634559
0.558802 -0.634559
0.638631 -0.634559
-0.739032 -0.531721
-0.656917 -0.531721
-0.574803 -0.531721
-0.492688 -0.531721
-0.410573 -0.531721
-0.328459 -0.531721
-0.246344 -0.531721
-0.164229 -0.531721
-0.0821147 -0.531721
0 -0.531721
0.0821147 -0.531721
0.164229 -0.531721
0.246344 -0.531721
0.328459 -0.531721
0.410573 -0.531721
0.492688 -0.531721
0.574803 -0.531721
0.656917 -0.531721
-0.755783 -0.42728
-0.671807 -0.42728
-0.587831 -0.42728
-0.503855 -0.42728
-0.41988 -0.42728
-0.335904 -0.42728
-0.251928 -0.42728
-0.167952 -0.42728
-0.0839759 -0.42728
0 -0.42728
0.0839759 -0.42728
0.167952 -0.42728
0.251928 -0.42728
0.335904 -0.42728
0.41988 -0.42728
0.503855 -0.42728
0.587831 -0.42728
0.671807 -0.42728
-0.768765 -0.321566
-0.683346 -0.321566
-0.597928 -0.321566
-0.51251 -0.321566
-0.427092 -0.321566
-0.341673 -0.321566
-0.256255 -0.321566
-0.170837 -0.321566
-0.0854183 -0.321566
0 -0.321566
0.0854183 -0.321566
0.170837 -0.321566
0.256255 -0.321566
0.341673 -0.321566
0.427092 -0.321566
0.51251 -0.321566
0.597928 -0.321566
0.683346 -0.321566
-0.778013 -0.214902
-0.691567 -0.214902
-0.605121 -0.214902
-0.518675 -0.214902
-0.43223 -0.214902
-0.345784 -0.214902
-0.259338 -0.214902
-0.172892 -0.214902
-0.0864459 -0.214902
0 -0.214902
0.0864459 -0.214902
0.172892 -0.214902
0.259338 -0.214902
0.345784 -0.214902
0.43223 -0.214902
0.518675 -0.214902
0.605121 -0.214902
0.691567 -0.214902
-0.783553 -0.107608
-0.696492 -0.107608
-0.60943 -0.107608
-0.522369 -0.107608
-0.435307 -0.107608
-0.348246 -0.107608
-0.261184 -0.107608
-0.174123 -0.107608
-0.0870615 -0.107608
0 -0.107608
0.0870615 -0.107608
0.174123 -0.107608
0.261184 -0.107608
0.348246 -0.107608
0.435307 -0.107608
0.522369 -0.107608
0.60943 -0.107608
0.696492 -0.107608
-0.785398 0
-0.698132 0
-0.610865 0
-0.523599 0
-0.436332 0
-0.349066 0
-0.261799 0
-0.174533 0
-0.0872665 0
0 0
0.0872665 0
0.174533 0
0.261799 0
0.349066 0
0.436332 0
0.523599 0
0.610865 0
0.698132 0
-0.783553 0.107608
-0.696492 0.107608
-0.60943 0.107608
-0.522369 0.107608
-0.435307 0.107608
-0.348246 0.107608
-0.261184 0.107608
-0.174123 0.107608
-0.0870615 0.107608
0 0.107608
0.0870615 0.107608
0.174123 0.107608
0.261184 0.107608
0.348246 0.107608
0.435307 0.107608
0.522369 0.107608
0.60943 0.107608
0.696492 0.107608
-0.778013 0.214902
-0.691567 0.214902
-0.605121 0.214902
-0.518675 0.214902
-0.43223 0.214902
-0.345784 0.214902
-0.259338 0.214902
-0.172892 0.214902
-0.0864459 0.214902
0 0.214902
0.0864459 0.214902
0.172892 0.214902
0.259338 0.214902
0.345784 0.214902
0.43223 0.214902
0.518675 0.214902
0.605121 0.214902
0.691567 0.214902
-0.768765 0.321566
-0.683346 0.321566
-0.597928 0.321566
-0.51251 0.321566
-0.427092 0.321566
-0.341673 0.321566
-0.256255 0.321566
-0.170837 0.321566
-0.0854183 0.321566
0 0.321566
0.0854183 0.321566
0.170837 0.321566
0.256255 0.321566
0.341673 0.321566
0.427092 0.321566
0.51251 0.321566
0.597928 0.321566
0.683346 0.321566
-0.755783 0.42728
-0.671807 0.42728
-0.587831 0.42728
-0.503855 0.42728
-0.41988 0.42728
-0.335904 0.42728
-0.251928 0.42728
-0.167952 0.42728
-0.0839759 0.42728
0 0.42728
0.0839759 0.42728
0.167952 0.42728
0.251928 0.42728
0.335904 0.42728
0.41988 0.42728
0.503855 0.42728
0.587831 0.42728
0.671807 0.42728
-0.739032 0.531721
-0.656917 0.531721
-0.574803 0.531721
-0.492688 0.531721
-0.410573 0.531721
-0.328459 0.531721
-0.246344 0.531721
-0.164229 0.531721
-0.0821147 0.531721
0 0.531721
0.0821147 0.531721
0.164229 0.531721
0.246344 0.531721
0.328459 0.531721
0.410573 0.531721
0.492688 0.531721
0.574803 0.531721
0.656917 0.531721
-0.718459 0.634559
-0.638631 0.634559
-0.558802 0.634559
-0.478973 0.634559
-0.399144 0.634559
-0.319315 0.634559
-0.239486 0.634559
-0.159658 0.634559
-0.0798288 0.634559
0 0.634559
0.0798288 0.634559
0.159658 0.634559
0.239486 0.634559
0.319315 0.634559
0.399144 0.634559
0.478973 0.634559
0.558802 0.634559
0.638631 0.634559
-0.693994 0.735453
-0.616883 0.735453
-0.539773 0.735453
-0.462663 0.735453
-0.385552 0.735453
-0.308442 0.735453
-0.231331 0.735453
-0.154221 0.735453
-0.0771104 0.735453
0 0.735453
0.0771104 0.735453
0.154221 0.735453
0.231331 0.735453
0.308442 0.735453
0.385552 0.735453
0.462663 0.735453
0.539773 0.735453
0.616883 0.735453
-0.665538 0.83405
-0.591589 0.83405
-0.51764 0.83405
-0.443692 0.83405
-0.369743 0.83405
-0.295795 0.83405
-0.221846 0.83405
-0.147897 0.83405
-0.0739486 0.83405
0 0.83405
0.0739486 0.83405
0.147897 0.83405
0.221846 0.83405
0.295795 0.83405
0.369743 0.83405
0.443692 0.83405
0.51764 0.83405
0.591589 0.83405
-0.632958 0.929977
-0.562629 0.929977
-0.492301 0.929977
-0.421972 0.929977
-0.351643 0.929977
-0.281315 0.929977
-0.210986 0.929977
-0.140657 0.929977
-0.0703287 0.929977
0 0.929977
0.0703287 0.929977
0.140657 0.929977
0.210986 0.929977
0.281315 0.929977
0.351643 0.929977
0.421972 0.929977
0.492301 0.929977
0.562629 0.929977
-0.596072 1.02284
-0.529842 1.02284
-0.463612 1.02284
-0.397381 1.02284
-0.331151 1.02284
-0.264921 1.02284
-0.198691 1.02284
-0.13246 1.02284
-0.0662302 1.02284
0 1.02284
0.0662302 1.02284
0.13246 1.02284
0.198691 1.02284
0.264921 1.02284
0.331151 1.02284
0.397381 1.02284
0.463612 1.02284
0.529842 1.02284
-0.554624 1.11219
-0.492999 1.11219
-0.431374 1.11219
-0.369749 1.11219
-0.308125 1.11219
-0.2465 1.11219
-0.184875 1.11219
-0.12325 1.11219
-0.0616249 1.11219
0 1.11219
0.0616249 1.11219
0.12325 1.11219
0.184875 1.11219
0.2465 1.11219
0.308125 1.11219
0.369749 1.11219
0.431374 1.11219
0.492999 1.11219
-0.508249 1.19755
-0.451777 1.19755
-0.395305 1.19755
-0.338833 1.19755
-0.28236 1.19755
-0.225888 1.19755
-0.169416 1.19755
-0.112944 1.19755
-0.0564721 1.19755
0 1.19755
0.0564721 1.19755
0.112944 1.19755
0.169416 1.19755
0.225888 1.19755
0.28236 1.19755
0.338833 1.19755
0.395305 1.19755
0.451777 1.19755
-0.456404 1.27835
-0.405692 1.27835
-0.354981 1.27835
-0.304269 1.27835
-0.253558 1.27835
-0.202846 1.27835
-0.152135 1.27835
-0.101423 1.27835
-0.0507115 1.27835
0 1.27835
0.0507115 1.27835
0.101423 1.27835
0.152135 1.27835
0.202846 1.27835
0.253558 1.27835
0.304269 1.27835
0.354981 1.27835
0.405692 1.27835
-0.398245 1.35389
-0.353996 1.35389
-0.309746 1.35389
-0.265497 1.35389
-0.221247 1.35389
-0.176998 1.35389
-0.132748 1.35389
-0.0884989 1.35389
-0.0442494 1.35389
0 1.35389
0.0442494 1.35389
0.0884989 1.35389
0.132748 1.35389
0.176998 1.35389
0.221247 1.35389
0.265497 1.35389
0.309746 1.35389
0.353996 1.35389
-0.332348 1.42323
-0.295421 1.42323
-0.258493 1.42323
-0.221566 1.42323
-0.184638 1.42323
-0.14771 1.42323
-0.110783 1.42323
-0.0738552 1.42323
-0.0369276 1.42323
0 1.42323
0.0369276 1.42323
0.0738552 1.42323
0.110783 1.42323
0.14771 1.42323
0.184638 1.42323
0.221566 1.42323
0.258493 1.42323
0.295421 1.42323
-0.255988 1.48502
-0.227545 1.48502
-0.199102 1.48502
-0.170659 1.48502
-0.142216 1.48502
-0.113772 1.48502
-0.0853293 1.48502
-0.0568862 1.48502
-0.0284431 1.48502
0 1.48502
0.0284431 1.48502
0.0568862 1.48502
0.0853293 1.48502
0.113772 1.48502
0.142216 1.48502
0.170659 1.48502
0.199102 1.48502
0.227545 1.48502
-0.162455 1.53683
-0.144405 1.53683
-0.126354 1.53683
-0.108304 1.53683
-0.0902529 1.53683
-0.0722023 1.53683
-0.0541518 1.53683
-0.0361012 1.53683
-0.0180506 1.53683
0 1.53683
0.0180506 1.53683
0.0361012 1.53683
0.0541518 1.53683
0.0722023 1.53683
0.0902529 1.53683
0.108304 1.53683
0.126354 1.53683
0.144405 1.53683
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment