# 3d sphere coord in 2d

This topic is 4857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, I need to project a point on a 3d sphere in a 2d view. Here is the information I have: Bearing & Mark (in degrees) and Radius. Now, I could figure out the location in 3d space (X,Y,Z) and then make a projection matrix to project that onto a 2d surface. I understand all that. What I'm asking here is a simpler way to handle it, since the camera is fixed in this case- straight on the sphere. Is there a simpler way to handle this scenario? Thanks

##### Share on other sites
Don't know if it is simpler but you could fire a ray from the camera through the point and find the point of intersection with your 2D surface (plane).

This is pretty straightforward and probably cheaper than setting up a matrix and performing a projection.

Just an idea...

Regards!
/hObbE

##### Share on other sites
You can project a sphere to screen coordinates using w for calcule radius.
I've got a code from my engine. Let's see:

bool GLeonCamera::ProjectSphere(GLEON_VECTOR3 * origin, GLEON_REAL radius, GLEON_VECTOR3 * projorigin, GLEON_REAL &projradius){	GLEON_VECTOR3 vtemp;	GLEON_VECTOR4 v4temp,v4temp2;	GLEON_VECTOR4 cameraplane;			GLEON_REAL rtemp;			GetFrustumPlane(CONSTGLEON_FRUSTUMBACK,&cameraplane);/////if sphere lie behind of the near plane, don't apply perspective //////transformation	rtemp = GLeonMath::DistancePlanePoint(&cameraplane,origin);	if(GLeonMath::IsNegative(rtemp)==false)	{          GLeonMath::Matrix4TransformVec3(            &vtemp,            origin,            &m_world_to_camera);			    projorigin->x = (1.0f + vtemp.x)*0.5f;	    projorigin->y = -(1.0f + vtemp.y)*0.5f;	    projorigin->z = vtemp.z; 	    projradius = radius;	    return true;	}		///////but if sphere is visible, then apply perspective transformation		               v4temp.x = origin->x;	v4temp.y = origin->y;	v4temp.z = origin->z;	v4temp.w = 1.0f;	///project point        ////total transform is m_matProjection*m_world_to_camera	                       GLeonMath::Matrix4TransformVec4(&v4temp2,&v4temp,&m_totaltransform);		if(GLeonMath::IsZero(v4temp2.w))	{			return false;////invalid value	}		projorigin->x = (1.0f + v4temp2.x/v4temp2.w)*0.5f;///scale with W	projorigin->y = (1.0f + v4temp2.y/v4temp2.w)*0.5f;///scale with W	projorigin->z = m_ScissorN+  -rtemp;///ScissorN is the near plane                                                  ///distance	projradius = radius/v4temp2.w;///scale with W		return true;        ///returns  a point that x lies in range [0,1]        /// y lies in range [0,1] with y axis pointing down( text direction)        //// and z lies in range [m_frustumN,m_frustumF]}

##### Share on other sites
You can check out polar coordinate systems. As far I can see they capture exactly what you want to express.

Greetz,

Illco

##### Share on other sites
Illco, ok I can see that. Basically I'm using 2 polar systems in conjunction, one for mark and one for bearing. Hmmmm.

Ok, so now my head explodes on how to combine 2 of them to describe any point on the surface of a sphere...

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632984
• Total Posts
3009715
• ### Who's Online (See full list)

There are no registered users currently online

×