Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411423 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 18, 2024, 12:33:06 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)project or plot 2d points onto a 3d sphere???
Pages: [1]
Print
Author Topic: project or plot 2d points onto a 3d sphere???  (Read 8037 times)
XRA
Level 4
****

.


View Profile WWW
« on: January 29, 2011, 05:07:17 PM »

I've tried searching around but am a little lost still..

I'm creating some positions in 3d that create a plane..so they are really just 2d coordinates using X and Z initially.  I'd like to take this list of Vector3's and be able to distribute them along the surface of a sphere evenly, or mostly evenly, meaning as they wrap around the sphere the distance between their neighbors remains roughly the same as it is when they are on a plane.. it doesn't need to be ultra precise.

At first I was using an actual sphere and raycasting from each point to the center of the sphere, and then using the hit position.. but doing that you end up with a lot of points clumping together around the edge of the sphere.

When I first create the list of Vector3's for the points, I use a center point, and once all that is done, I align all the Vector3's with the angle from that center point and the center of the imaginary sphere... the next step would be adjusting each Vector3 so that it conforms to a radius, which really should just be the distance from the center spawn point and the center of the imaginary sphere.

any ideas? I'm still kinda new to vector math and stuff. Here is a diagram:
Logged

XRA
Level 4
****

.


View Profile WWW
« Reply #1 on: January 29, 2011, 05:21:17 PM »

hm this might be similar to texture mapping on a sphere, I'll post results if I figure it out.
Logged

gamesfrommars
Level 0
**


View Profile WWW
« Reply #2 on: January 29, 2011, 05:25:08 PM »

Here is an uniform mapping from a square to a sphere (not tested).

Code:

// Let x, y be a point on your plane (0..1).
function mapPlaneToSphere(x, y)
    z = -1 + 2 * x;
    phi = 2 * PI * y;
    theta = asin(z);
    return vector3(cos(theta) * cos(phi),
                   cos(theta) * sin(phi),
                   z);
Logged

mcc
Level 10
*****


glitch


View Profile WWW
« Reply #3 on: January 29, 2011, 06:43:50 PM »

So... as far as measuring "evenly" goes... here's a distance function. Keep in mind that you will not be able to map from a flat surface to a curved surface while preserving both distance and angles.

Instead of starting in flat space and mapping to the sphere, might it make more sense to just move around on the surface of the sphere and place points there? For example place things at spherical coordinate points, or place one object and then rotate the sphere and repeat.
Logged

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #4 on: January 29, 2011, 08:12:59 PM »

you can just read the plane coordinate like angle coordinate.
The x would be longitude and y the latitude.

Now you just need to project the "egde" (max/min dimension that contain all the point) of the plane on the circle and derive their new coordinate.

There is two way:

1-You directly project the extremum onto the circle by tracing a line from the center of the sphere to that extremum and finding the point that correspond to the radii in that line. Repeat for each extremum and they became the angular extremum of the new surface. Of course I suppose the surface is conveniently tangent to the sphere surface first (you can place it there at the beginning).

2-The other method involve calculating the dimension (height and width) of the containing surface of the plane. Use those dimension as the arc dimension of the sphere and derive the angle of that arc for each. Then find take that angle and find the extremum angular coordinate. It have the effect of wrapping instead of projecting like the first method. However you may have to handle case where it wrap multiple time.


From there you derive angular coordinate of points by proportionally converting their plane coordinates. It's easier also if you find the center of the plane first and use that center to position the surface onto the sphere, every point would be an offset of that center and it allow you to scale the dimension without problem.
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #5 on: January 30, 2011, 02:06:20 AM »

As mcc says, you must pick a mapping that has the attributes you want. You want an even distribution of points on the plane to become an even distribution of points on the sphere - this is called area preserving.

I cannot find a proof on the internet, and cannot be bothered to derive, but I believe what you want is the simpler cylindrical co-ordinates.

Here's the formula:
Code:
// x and y in [0,1]
function mapFromPlaneToSphere(x,y)
{
// Map uniformly onto cylinder along z axis of radius 1 and height from -1 to 1
// as expressed in cylindrical co-ordinates
phi = y * 2 * PI
z = 2 * x - 1
rho = 1
// Project that radially along z-axis to be on sphere
rho = sqrt(1-z*z)
// Convert to euclidian space
return Vec3(rho * cos(y), rho * sin(y), z)
}

Edit: On reflection, this is mathematically the same as gamesfrommars's solution. A bit faster, though.
« Last Edit: January 30, 2011, 02:27:30 AM by BorisTheBrave » Logged
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #6 on: January 30, 2011, 02:11:02 AM »

Note: I do not think this is the same thing textures do - this mapping heavily distorts the texture at the poles (while still preserving area, though). It's more common to map an irregular shape, or several shapes onto the sphere, so that each can cover a smaller part with no distortion.
Logged
XRA
Level 4
****

.


View Profile WWW
« Reply #7 on: January 30, 2011, 02:32:22 AM »

thanks for the replies, really helpful! i was all like this most of the day Hand Shake LeftEpilepticHand Shake Right

I ended up getting it working in a hacky way, bypassing probably some simpler math equations that I have no idea about,


**EDIT** ...still having trouble, i just noticed everything compresses down into a line when the spawner/center point object is moved across the Y axis (from positive to negative)


« Last Edit: January 30, 2011, 03:57:01 AM by XRA » Logged

XRA
Level 4
****

.


View Profile WWW
« Reply #8 on: January 30, 2011, 02:34:53 AM »

just saw there were two more replies, I'm going to try the cylindrical coordinates, I think what I may have done is a broken way of stereographic projection, I'm not too sure though.
Logged

XRA
Level 4
****

.


View Profile WWW
« Reply #9 on: January 30, 2011, 02:54:53 AM »

ahhhh I spoke too soon... some weird squishing happens when I move the spawn/center point close to what would be the "equator" on the sphere.. looks like the points cross over and flip probably because of something going negative



« Last Edit: January 30, 2011, 03:55:43 AM by XRA » Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic