# Thread: 2d coordintaes along edges

1. ## 2d coordintaes along edges

hi, can somebody help me out on these questions?

I am rendering an object using opengl. I understand that I can use glProject to get the actual 2d coordinates on the screen. But what if I only need the coordinates along the edges of the object(ie something like obtaining the outline of what I see on the screen)? How can I do this? I read somewhere about using scan lines to get the coordinates, is it feasible? Also, what is the precision of the coordinates? I read that it is up to 1 decimal place, is that true? Because I'll need to plot these values out on a x-y plot.

2. ## Re: 2d coordintaes along edges

Hi!

Actually the corner points are enough for you to calculate all of the coordinates alogn the edges. In the good ol' times we had to do all for ourselves. No OpenGL, no DirectX, just a 320x200 display ;-)
Well, using scanlines for your calculations is correct. Basically you have to calculate you coordinates for each edge. So if you have a triangle (12,10), (17,14) and (8,24), you have to follow each edge and calculate the dx - how much the x value changes when your y value changes for 1.
Example for the first edge (12,10) - (17,14):

x1=12; y1=10;
x2=17; y2=14;
dx=(x2-x1)/(y2-y1);
x=x1;
for (y=y1;y<y2;y++)
{
cout << "The x coordinate in row: " << y << " is: " << x << endl;
x=x+dx;
}

That's it. The precision depends on what type your "x" variable is. Make it a double and you get more precision than you'll ever need ;-)
If I wasn't clear try searching the web for "polygon drawing" or "line drawing algorithm"

Cheers

Firestar

3. ## Re: 2d coordintaes along edges

Hi Firestar,

Thanks for your reply. I now have a better understanding of how scanlines work, and also a clearer picture of how things are. But I see that I'll need to find the coordinates of all the corner points before I can proceed. You see, I am rendering an irregular object, something like a rock made up of lots of polygons, and there are thousands of vertices to consider. Each time I rotate the rock, I get a different outline and thus a new edge to consider. How can I make sure that I only get the corner points(vertices) along the rock's edge(ie the outline edge of what I see on the screen, which can be made up of many polygons), and not the inetrior points? In the end, I am interested only in the 2D outline of the rock, and the corresponding 2D coordinates.