Hold it! I just discovered I forgot to convert the output of Atan2 to degrees for use in Graphics.RotateTransform. Let's see if it fixes the problem. BB (+forhead-slapping)
[edit] It still doesn't work correctly, but at least the angle is now correct which I hope will make it easier to spot the problem.
The reason I noticed the angle conversion error was that I decided to have a quick go at making a 2F+P ellipse tool as suggested by Logophobic. I used a VB.Net version of the pins-and-string method. It worked on the first attempt, except (for now obvious reasons) the angle. The completed code for the 2F+P ellipse is as follows:
The Distance function calculates Math.Sqrt(dX^2+dY^2). See the attached zip for full VB.Net code with a test form. The ellipse tools and the LabelledPoint are now in separate files from the test form.Code:Public Shared Function FindEllipse2(F1 As PointF, F2 As PointF, P As PointF) As EllipseTools.EllipseArguments Dim ea As EllipseTools.EllipseArguments ea.centre = New PointF((F1.X + F2.X) / 2.0F, (F1.Y + F2.Y) / 2.0F) Dim f As Double = Distance(F1, F2) / 2 ea.A = CSng((Distance(F1, P) + Distance(P, F2)) / 2.0F) 'half the length of the "string" ea.B = CSng(Math.Sqrt(ea.A ^ 2 - f ^ 2)) ea.angle = CSng(Math.Atan2(F2.Y - F1.Y, F2.X - F1.X) * 180 / Math.PI) Return ea End Function
edit several weeks later: on reviewing the thread, I just noticed that I accidentally deleted the Dim f line from the code posted above at some point. Now I have put it back. My apologies to anyone who tried running it. The zip should still be OK.




Reply With Quote