We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Spherical projection from points cloud
Page Index Toggle Pages: 1
Spherical projection from points cloud (Read 900 times)
Spherical projection from points cloud
Jan 23rd, 2010, 7:08pm
 
Hey there,

Lately I was able of create a spherical projection from a 3D coordinates, but I´m missing on how to add the original Z vector to the created spherical vector Z'

has anyone done this before?

Code:


// convert lat/long to radians
float latitude = PI * p.x / 180;
float longitude = PI * p.y / 180;
   
// adjust position by radians
floa latitude -= radians(90); // subtract 90 degrees (in radians)

x = (radius) * sin(latitude) * cos(longitude);
y = (radius) * sin(latitude) * sin(longitude);

// how can I add to this vector the original z cords (p.z) ?
z = (radius) * cos(latitude);



Thanks.


Re: Spherical projection from points cloud
Reply #1 - Jan 23rd, 2010, 7:14pm
 
We're actually discussing this in another thread.. I'm still trying to work it out but maybe you'll take it over the finish line.

http://processing.org/discourse/yabb2/?num=1259917547/15
Re: Spherical projection from points cloud
Reply #2 - Jan 23rd, 2010, 8:11pm
 
thanks Jeff,

I gived it a try to the example on that link but I`m not sure if its suitable for my problem, on wich the Z vector is first calculated based on pixel brightness from Video webcam, I`ve  failed to add that vector to the Z vector on the sphere Sad

Here`s my full code.

Code:


import processing.opengl.*;
import processing.video.*;
import peasy.*;

PeasyCam pCamera;
PImage a;
int squareList;
// Size of each cell in the grid/sphere
int cellSize = 8;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;


void setup() {

 size(600, 600, OPENGL);
 
 //hint( ENABLE_OPENGL_4X_SMOOTH );  
 //smooth();

 cols = width / cellSize;
 rows = height / cellSize;
 colorMode(RGB, 255, 255, 255, 100);

 fill(255,255,255,75);

 pCamera = new PeasyCam(this, 0, 0, 0, width/2);

 // Uses the default video input, see the reference if this causes an error
 video = new Capture(this, width, height, 12);
}


void draw() {

 background(0);
 
 if (video.available()) {
   video.read();
   video.loadPixels();
   
   float radius = width/2;

   // Begin loop for columns
   for (int i = 0; i < cols; i++) {
     // Begin loop for rows

     for (int j = 0; j < rows; j++) {

       // Where are we, pixel-wise?
       int x = i*cellSize;
       int y = j*cellSize;
       float z;

       int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image

       float r = red(video.pixels[loc]);
       float g = green(video.pixels[loc]);
       float b = blue(video.pixels[loc]);
       
       // Make a new color with an alpha component
       color c = color(r, g, b, 100);
       float z1 = brightness(video.pixels[loc]);
       
       
       //------------<< Spherical projection !
//uncomment
       
       /*
       // convert lat/long to radians
       float latitude = PI * x / 180;
       float longitude = PI * y / 180;

       // adjust position by radians
       // subtract 90 degrees (in radians)
       latitude -= radians(90);
       
       x = (int)((radius) * sin(latitude) * cos(longitude));
       y = (int)((radius) * sin(latitude) * sin(longitude));        
       z = (int)(radius * sin(latitude) * cos(longitude));
       */
       
       //--------------Spherical projection >> !
       
       fill(c);
       pushMatrix();
       translate(x,y,z1);        
       ellipse(0,0, cellSize,cellSize);
       popMatrix();


     }//end for
   }
 }
}




Appreciate any help
Thank u.
Page Index Toggle Pages: 1