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

## 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.x=radius*sin(10*i*PI/180); points.y=0; points.z=radius*cos(10*i*PI/180); points[i+36].x=points.x; points[i+36].y=-height; points[i+36].z=points.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 on other sites
if you are using 180 and not 180.0 or 180f then the value might get cast to integer implictly.

hope that helps

##### Share on other sites
Quote:
 Original post by n0rmanfreakif 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.

1. 1
2. 2
3. 3
Rutin
25
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633649
• Total Posts
3013117
×