Sign in to follow this  
billyyu

Ask a question about transform Bounding Spheres

Recommended Posts

I have built some bounding shperes for an articulated robot, and when the robot moves, the angles of each link change as well. I use the OpenGL to build the model, the shafts are built by the command glCylinder(), then I transform the cylinders into some set of points, the code is as follow:(PI is defined as 3.1415926) void CModel::Vertex_Cylinder(point points[], float radius, float height) { for(int i=0;i<36;i++) { points[i].x=radius*sin(10*i*PI/180); points[i].y=0; points[i].z=radius*cos(10*i*PI/180); points[i+36].x=points[i].x; points[i+36].y=-height; points[i+36].z=points[i].z; } } And then I use the typical method to find the center and the radius for the sphere. Till now everything is ok and the spheres are bounded these shafts, but as the angles change, the center is in the right position and the radius magnifies from time to time. At first i thought maybe it's the accuracy of the data type and i replaced the 'float' with 'double', and the result is the same. The rotate code is as follow: void CModelView::RotateX(Vector3 *ptr,float angle) { float x,y,z; x=ptr->x; y=ptr->y; z=ptr->z; ptr->x= x; ptr->y= y*cos(angle*PI/180)+z*sin(angle*PI/180); ptr->z=-y*sin(angle*PI/180)+z*cos(angle*PI/180); } void CModelView::RotateY(Vector3 *ptr,float angle) { float x,y,z; x=ptr->x; y=ptr->y; z=ptr->z; ptr->x= x*cos(angle*PI/180)-z*sin(angle*PI/180); ptr->y= y; ptr->z=x*sin(angle*PI/180)+z*cos(angle*PI/180); } void CModelView::RotateZ(Vector3 *ptr,float angle) { float x,y,z; x=ptr->x; y=ptr->y; z=ptr->z; ptr->x=float(x*cos(angle*PI/180)-y*sin(angle*PI/180)); ptr->y=float(x*sin(angle*PI/180)+y*cos(angle*PI/180)); ptr->z=float(z); } Can anyone help me?

Share this post


Link to post
Share on other sites
Quote:
Original post by n0rmanfreak
if you are using 180 and not 180.0 or 180f then the value might get cast to integer implictly.

hope that helps


I used the 180.0 instead of 180, but things didnot turn well, the problem is still there, is there any other suggestion? Thank you for you patience.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this