I am a beginner in CAD development & want to know some things about OpenGL. My main objective is to represent conics, cycloid, epicycloid, hypocycloid, involutes, etc Can i directly represent them using some trigonometry, or do i need to convert these curves into B-Spline? Actually i am currently developing the kernel & want to develop the kernel so that i cant display the above mentioned curves.(there is no use in supporting these curves in kernel if i cant graphically represent them!) I dont know much about OpenGL, so please pardon me if my question is really stupid! I tried searching over here but could not find anything useful.
2 Answers
OpenGL can directly render Bezier curves and surfaces using evaluators and even NURBS using the GLU API. See the OpenGL Programming Guide for more information. So you could transform those curves and surfaces into this form.
But I highly recommend you not to use these features, as they are deprecated (dropped from the core of newer OpenGL versions) and nowadays likely to be implemented in software and not in hardware.
Instead you should rather implement your own evaluation routines for such curves and surfaces, that evaluate the corresponding equations at a specified sampling rate and generate a simple vertex array (and maybe and index array). This way you stay future-ready as these can be rendered as standard line strips or triangular meshes using VBOs (the only way to render something in modern OpenGL).
And you even stay API agnostic, as a general vertex array can also be rendered using Direct3D or whatever. So this way you don't pollute your CAD kernel with draw calls. All it needs is a function to transform parametric curves and surfaces into arrays of vertices (and maybe indices) and the client/user of the kernel is responsible for drawing these with whatever API he likes.

- 45,360
- 10
- 108
- 185
If I am not wrong, OpenGL only works with flat polygons. Even though, you can check if the GLUT libraries have any method to draw the aforementioned figures, or google for a .obj of those figures, and scale, rotate and translate them to the desired position.

- 45,360
- 10
- 108
- 185

- 669
- 1
- 8
- 17
-
2You can easily use opengl and direct3d to render lines, points or polygons, i.e. you are not limited to polygons. The only problem is you need to discredize the line into vertices and tell the graphics api to draw lines between them. – edvaldig Oct 31 '11 at 12:40
-
That's what a .obj is meant to. It contains the vertices and faces of the object, and you can perform a scale, translation and rotation, so you can reuse a single .obj to construct as many different figures as you want. – Josep Rodríguez López Oct 31 '11 at 12:45
-
2@JosepRodríguezLópez But you don't neccessarily need an .obj or any file. If you have a parametric representation you can just evaluate it at discrete samples. This would probably work better in a CAD program than loading fixed models, at least if the curves/surfaces get more complicated, like NURBS. – Christian Rau Oct 31 '11 at 13:16
-
@ChristianRau, so if i have to draw an arc with centre at origin & from X axis to Y axis in the first quadrant how many "discrete samples" do i need to provide so that the arc looks an arc & not a polyline??? – Cool_Coder Oct 31 '11 at 13:30
-
@JosepRodríguezLópez You obviously misunderstand the problem as .obj is a file format for storing 3d model data (vertices, faces, materials, uv, etc.). If you for some reason would like to discretize a 2d or 3d function into a list of vertices and save it to a file for loading later, then sure you could save it in an .obj file, but why bother with the overhead i don't know... – edvaldig Oct 31 '11 at 14:30
-
@CAD_coding Normally you would include a parameter, e.g. #steps which controls the "smoothness" of the line. I think you can actually find a corresponding parameter in some 3d software packages when working with lines. In your case it would simply control how many samples on a given interval you take. – edvaldig Oct 31 '11 at 14:35
-
1I pointed out the .obj file just in case GLUT didn't provide any function to draw those figures, but in case a library provides them, obviously it can be faster than reading files. In case you don't find a GLUT method, may be you could create the function yourself. – Josep Rodríguez López Oct 31 '11 at 15:36