pixuk
asked on
Plotting a circle with system.drawing including rotated labels
I am trying to use system.drawing to draw a circle divided into a variable amount of points, with a text label at each of the points, preferably at an angle matching the current point on the circle (so the labels 'fan out' from the center).
Before I attempt to try and stitch this into my database backend, the first thing I'm trying to do is simply draw the circle as a series of connected points. Something along these lines
for t = 1 to 360 step 10
x = cos(t)
y = sin(t)
pts(cpt) = New Point(x,y)
next
g.DrawCurve(New Pen(Color.Red), pts, 0.8F)
Although obviously with a bit more too it than that. However, I don't think my maths is quite up to the task, and the above method doesn't take into account the labels, so probably isn't the way to go anyway.
I should make it clear I'm not just trying to draw a circle - I'm trying to plot points and arrange them in a circle, if that makes sense.
Been searching Google, but can't really find anything about drawing a circle from scratch.
Before I attempt to try and stitch this into my database backend, the first thing I'm trying to do is simply draw the circle as a series of connected points. Something along these lines
for t = 1 to 360 step 10
x = cos(t)
y = sin(t)
pts(cpt) = New Point(x,y)
next
g.DrawCurve(New Pen(Color.Red), pts, 0.8F)
Although obviously with a bit more too it than that. However, I don't think my maths is quite up to the task, and the above method doesn't take into account the labels, so probably isn't the way to go anyway.
I should make it clear I'm not just trying to draw a circle - I'm trying to plot points and arrange them in a circle, if that makes sense.
Been searching Google, but can't really find anything about drawing a circle from scratch.
ASKER
Thanks for the tip, but to be honest, at this stage I'm not actually that bothered about the accuracy of the point position - the first thing I need to do is draw a circle, and the snippet above didn't seem to do the trick.
Just to re-iterate the question; I want to draw a circle, and at a variable number of points around it, put text labels at an angle equivalent to that point on the circle.
Just to re-iterate the question; I want to draw a circle, and at a variable number of points around it, put text labels at an angle equivalent to that point on the circle.
yes, but the problem is 0<cos(x) <1, so putting it in a Point object will force it to round off to 0 or 1
How about you put 100cos(x) into the point?
How about you put 100cos(x) into the point?
ASKER
I see what your saying. Do you have an example of code which draws a circle using PointF?
Do you know how to draw text at an angle?, assuming, of course, I can get that far!
Do you know how to draw text at an angle?, assuming, of course, I can get that far!
PointF, just exactly the same as what you are doing :)
Just declare PointF instead of Point
Also, I think multiplying your co-ordinates will help, otherwise your circle will be too small??
Ummm.... drawing text at an angle
I would try drawing text on a Bitmap first, then apply a transform filter to it. Try googling for "rotating an image with VB.Net"
Just declare PointF instead of Point
Also, I think multiplying your co-ordinates will help, otherwise your circle will be too small??
Ummm.... drawing text at an angle
I would try drawing text on a Bitmap first, then apply a transform filter to it. Try googling for "rotating an image with VB.Net"
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thanks, I think it's a bit mean to give a C though... I did answer the original question
You can do a debug.print(pts(cpt).x & " " & pts(cpt).y) to verify that