Jump to content
  • Advertisement
Sign in to follow this  
Roof Top Pew Wee

Drawing circles with Line Class (MDX) causing missing sections.

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a method (using C# and MDX by the way) that takes a list of points and draws polygons. I have a method that creates a circle by incrementing an angle and adding points using sin/cos methods. The typical circle drawing stuff. When I draw a line of 1 width everything's fine, but when I increase the width, the outside of the circle is missing thin slices. This is of course because thick lines become rectangles, and the "rectangles" connect at the center rather than the outside edges. Took a pic of a 1 width and a thicker circle: Free Image Hosting at www.ImageShack.us I know what the cause is, but what would be the easiest way to solve this problem if I were to still use the Line class? Has anyone tried to solve this before? --Vic--

Share this post


Link to post
Share on other sites
Advertisement
My first thought was to merely make each line longer, such that they overlap more, sufficiently to have their outer edges match up, rather than then centers. I belive the length that needs to be added to each side of a line is

ext = tan(d_theta / 2) * w / 2

where d_theta is the angle between each pair of adjacent points, and w is the thickness of the line. I'd draw a diagram in Paint, but I'm lazy. A little bit of trig and triangle drawing on paper will get you this result pretty quickly anyway.

So then you need to calculate how to take the single number you derived above to extend the edge of each line that amount, in the proper direciton. For any given line, I'm assuming you have the angles that were used for both points that define the line. If so, then you can get the actual angle of the line itself by using

theta_avg = (theta_0 + theta_1) / 2 + pi / 2 = (theta_0 + theta_1 + pi) / 2

Now that you know the angle of the line, then on one end you can calculate the new x and new y using

x_new = x_old + cos(theta_avg) * ext
y_new = y_old + sin(theta_avg) * ext

And on the other end of the line, very similar

x_new = x_old - cos(theta_avg) * ext
y_new = y_old - sin(theta_avg) * ext

Yeah, diagrams would help, I know. Of course, as you probably realize, the way to do this best would be to draw your own trapezoids (two triangles, naturally), so that everything matched up perfectly, rather than overlapping rectangles to make it look that way. I think the math would be computationally simpler as well, instead of doing circle calculations, and then extensions that I described above, you'd merely to two sets of circle calculations: the outside set of points, and the inside set of points.

Share this post


Link to post
Share on other sites
Yeah, I'm comfortable with the trig and theory behind extending the lines so that they match up, but if I'm to use the Line class and pass a group of vertices, I only have control over the vertices and not the actual lines. That is, if I were to do it like you suggested, I'd have to extend the first line by the given distance, them come back so that the next line extends far enough. This in effect doubles the number of lines that I have to draw. Perhaps it's the only way.

--Vic--

Share this post


Link to post
Share on other sites
Quote:
Original post by Roof Top Pew Wee
Yeah, I'm comfortable with the trig and theory behind extending the lines so that they match up, but if I'm to use the Line class and pass a group of vertices, I only have control over the vertices and not the actual lines. That is, if I were to do it like you suggested, I'd have to extend the first line by the given distance, them come back so that the next line extends far enough. This in effect doubles the number of lines that I have to draw. Perhaps it's the only way.

--Vic--


Ah, yes, I'm not too familar with the Line class. Does it allow you to draw line lists instead of simple line strips? Because that's what will be needed, unless the Line class contains some form of corner rounding option I don't know about. Aside from that, there's the do-it-yourself method.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!