Was trying something like this:
But my curves were all wrong…And I ended up with something like this.
The code is inserted below:
float angle;
float r = 200;
Table table;
PImage earth;
PShape globe;
int rowCount;
void setup() {
background(51);
size(600, 600, P3D);
table = new Table("From_USA_Coordinates.tsv");
rowCount = table.getRowCount();
earth = loadImage("world.topo.bathy.200406.3x5400x2700.jpg");
noStroke();
globe = createShape(SPHERE, r);
globe.setTexture(earth);
}
void draw() {
background(51);
text("From USA to other Parts of the World", width/2, 50);
textAlign(CENTER);
translate(width/2, height/2);
//rotateY(angle);
//angle += 0.005;
//lights();
noStroke();
shape(globe);
for(int row = 0; row < rowCount; row++){
float USALatitude = table.getFloat(row, 3);
float USALongitude = table.getFloat(row, 4);
float tripCountryLatitude = table.getFloat(row, 5);
float tripCountryLongitude = table.getFloat(row, 6);
int tripCountryOccurance = table.getInt(row, 2);
float tripTheta = radians(tripCountryLatitude);
float tripPhi = radians(tripCountryLongitude) + PI;
float USATheta = radians(USALatitude);
float USAPhi = radians(USALongitude);
float x1 = r * cos(USATheta) * cos(USAPhi);
float y1 = -r * sin(USATheta);
float z1 = -r * cos(USATheta) * sin(USAPhi);
float x2 = r * cos(tripTheta) * cos(tripPhi);
float y2 = -r * sin(tripTheta);
float z2 = -r * cos(tripTheta) * sin(tripPhi);
pushMatrix();
noFill();
stroke(255);
bezier(x1, y1, z1, x1+150, y1+240, z1+150, x2-300, y2-150, z2-190, x2, y2, z2);
popMatrix();
}
noLoop();
}
Table Class:
class Table {
int rowCount;
String[][] data;
Table(String filename) {
String[] rows = loadStrings(filename);
data = new String[rows.length][];
for (int i = 0; i < rows.length; i++) {
if (trim(rows[i]).length() == 0) {
continue; // skip empty rows
}
if (rows[i].startsWith("#")) {
continue; // skip comment lines
}
// split the row on the tabs
String[] pieces = split(rows[i], TAB);
// copy to the table array
data[rowCount] = pieces;
rowCount++;
// this could be done in one fell swoop via:
//data[rowCount++] = split(rows[i], TAB);
}
// resize the 'data' array as necessary
data = (String[][]) subset(data, 0, rowCount);
}
int getRowCount() {
return rowCount;
}
// find a row by its name, returns -1 if no row found
int getRowIndex(String name) {
for (int i = 0; i < rowCount; i++) {
if (data[i][0].equals(name)) {
return i;
}
}
println("No row named '" + name + "' was found");
return -1;
}
String getRowName(int row) {
return getString(row, 0);
}
String getString(int rowIndex, int column) {
return data[rowIndex][column];
}
String getString(String rowName, int column) {
return getString(getRowIndex(rowName), column);
}
int getInt(String rowName, int column) {
return parseInt(getString(rowName, column));
}
int getInt(int rowIndex, int column) {
return parseInt(getString(rowIndex, column));
}
float getFloat(String rowName, int column) {
return parseFloat(getString(rowName, column));
}
float getFloat(int rowIndex, int column) {
return parseFloat(getString(rowIndex, column));
}
void setRowName(int row, String what) {
data[row][0] = what;
}
void setString(int rowIndex, int column, String what) {
data[rowIndex][column] = what;
}
void setString(String rowName, int column, String what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = what;
}
void setInt(int rowIndex, int column, int what) {
data[rowIndex][column] = str(what);
}
void setInt(String rowName, int column, int what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = str(what);
}
void setFloat(int rowIndex, int column, float what) {
data[rowIndex][column] = str(what);
}
void setFloat(String rowName, int column, float what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = str(what);
}
}
Link to my data set:
And finally the link to the earth texture in sphere: