Trying to correct distortion wrapping 2D data image to 3D sphere
in
Programming Questions
•
1 year ago
Hi Folks,
I'm trying to map data using Processing and then distort it so that appears correctly when wrapped to a 3D globe in Cinema4D. For example, here's some mapped data in 2D and 3D. Notice the distortion in the second image as it gets towards the poles, circles turn to ovals:
I'm using an equirectangular projection which requires forms to widen as they get closer to the poles (which is why things get skinnier closer to the poles in the 3D image). An example of this distortion can be found here: http://en.wikipedia.org/wiki/File:Tissot_indicatrix_world_map_equirectangular_proj.svg ...
I have an equation that should correct for this distortion (more or less) that I have tried to use to distort the original 2D bitmap at top. My code takes each line of pixels, starting at the top and continuing line by line, and widens them accordingly. Here's the code followed by the outcome:
I think the problem here is that the forms as well as the spaces between them are being widened...creating the hourglass effect.
I think it would not be difficult to supplement the code that created the original 2D image with the code that distorts forms, solving the problem (although I'm not sure how to distort the text yet).
However, I have a collection of other bitmaps (not created in Processing) that map data that I would also like to distort and wrap to a 3D globe. So, does anyone have any other ideas for how I might distort this bitmap to wrap correctly?
Many thanks!
corndawg
I'm trying to map data using Processing and then distort it so that appears correctly when wrapped to a 3D globe in Cinema4D. For example, here's some mapped data in 2D and 3D. Notice the distortion in the second image as it gets towards the poles, circles turn to ovals:
I'm using an equirectangular projection which requires forms to widen as they get closer to the poles (which is why things get skinnier closer to the poles in the 3D image). An example of this distortion can be found here: http://en.wikipedia.org/wiki/File:Tissot_indicatrix_world_map_equirectangular_proj.svg ...
I have an equation that should correct for this distortion (more or less) that I have tried to use to distort the original 2D bitmap at top. My code takes each line of pixels, starting at the top and continuing line by line, and widens them accordingly. Here's the code followed by the outcome:
- PImage source;
PImage[] destination;
float lat;
float widthdistort;
float distortx;
void setup() {
source = loadImage("trans-final.png");
size(source.width, source.height);
noLoop();
destination = new PImage[source.height];
}
void draw() {
equirect(source);
}
//Equirectangular distort lines of pixels based on Tissot indicatrix approximation
void equirect(PImage source) {
for (int i = 0; i < source.height; i++) {
destination[i] = source.get(0, i, source.width, 1);
lat = map(i, 0, source.height, 90, -90);
widthdistort = (pow(lat/180.0, 2)*(source.width*9)) + source.width;
distortx = (widthdistort - source.width);
imageMode(CENTER);
image(destination[i], source.width/2, i, widthdistort, 1);
}
}
void keyPressed() {
if ((key == 'p') || (key == 'P')) {
saveFrame("frames/equirect_####.png");
}
}
I think the problem here is that the forms as well as the spaces between them are being widened...creating the hourglass effect.
I think it would not be difficult to supplement the code that created the original 2D image with the code that distorts forms, solving the problem (although I'm not sure how to distort the text yet).
However, I have a collection of other bitmaps (not created in Processing) that map data that I would also like to distort and wrap to a 3D globe. So, does anyone have any other ideas for how I might distort this bitmap to wrap correctly?
Many thanks!
corndawg
1