Solved

VB.Net DrawArc Inconsistent?

Posted on 2014-09-15
5
353 Views
Last Modified: 2014-09-22
I'm using DrawArc to create arc segments.  It's the usual "3 known points on a circle" routine.

When my graphics are oriented one direction, everything is fine (see below):

DrawArc-1.jpg
When I build the graphics with a different orientation, the segments are flipped around the x-axis (see below):

DrawArc-2.jpg
Note the values that are being sent to DrawArc(pen, rectangle, start, sweep).  In Condition #1, the start angle is 126° and the sweep angle is 106°.  The result is exactly what I would expect.

In Condition #2, the start angle is 216° and the sweep angle is 106°.  The data is correct; the result appears like the start angle and resulting arc are a mirror image of what they should be.  And this applies to all four arcs.  It's almost like something is adding 180° to the start angle.

I'm using the same call to DrawArc for both conditions.

If my baseline for arcs is on a 45° angle, I also get erroneous results, but it appears like something is adding 90° to the start angle.

Thank you in advance for any suggestions!

George
0
Comment
Question by:CIW_George
  • 2
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40330663
I sort of reproduced your project because I was intrigued... ;-)

Without seeing your code I'll start with some general remarks that might explain this, based on what you describe:

1) if you're using a 'standard' function to determine whether the sweep is clockwise or counter-clockwise then note that in maths generally the y axis starts at the bottom while in VB.NET it starts at the top so a function like that would give the 'reverse' result.

2) also note that your calculated angles seem to be based on starting (correctly) on the rightmost point of the circle but going counter-clockwise while the DrawArc documentation states it is defined as clockwise. In your first example it doesn't matter as all circles are intersected by the vertical line (from point 2 to 15), just the sweep angle would have to be reversed. But then of course if you combine this with the previous note, a 'flipped' canvas would negate this second note...!

Now after some trial and error I came up with the code below, which processes both your examples correctly as you can see in the image.
capture
                        Dim rct As RectangleF = GetCircle(x1, y1, x2, y2, x3, y3) ' circle from 3 points: http://www.regentsprep.org/Regents/math/geometry/GCG6/RCir.htm

                        Dim xcc As Single = rct.X + rct.Width / 2
                        Dim ycc As Single = rct.Y + rct.Height / 2

                        Dim reversesweep As Boolean = ccw(x1, y1, x2, y2, x3, y3) ' from http://en.wikipedia.org/wiki/Graham_scan

                        startangle = get_angle(x1 - xcc, y1 - ycc)
                        endangle = get_angle(x3 - xcc, y3 - ycc)
                        sweepangle = endangle - startangle
                        If reversesweep Xor (sweepangle > 0) Then sweepangle += -360 * Math.Sign(sweepangle)
                        gr.DrawArc(pn, rct, startangle, sweepangle)

Open in new window

Obviously, whether this helps you may depend largely on the compatibility of the called functions with yours. But for starters I think this bit together with the remarks above may enable you to determine the problem. If you think my exact implementation can help you further, please look at the attached project which by now includes some nice bells and whistles (like moving the individual points and calculate the result real-time).
prj.zip
0
 

Author Comment

by:CIW_George
ID: 40335790
Robert -

Thank you very much for your detailed response!  I sincerely appreciate the effort you put into it and it was very easy to follow.  Your sample is excellent!

I've still got an issue with Condition #2 - I can't get it to draw on the correct sweep.  I haven't had much time to work on it for the past couple days, but I believe I have your code integrated into my project correctly.  I suspect it may have something to do with the different coordinate systems in play.

As soon as I get the issue resolved, I'll update with the solution.

In the meantime, I will accept your answer as the solution and assume to problem is on my end.

Thank you!
0
 

Author Closing Comment

by:CIW_George
ID: 40335791
Excellent response - well documented and easy to follow.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 40336338
Ok, great. Well don't hesitate to post further questions here if you're still stuck on this. Probably best to share a bit of code in that case of course.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to deploy to IIS 7 on 2008R2 server with DUO 2-step login? 2 33
Server Error 11 47
Error on link 14 36
Get the selected ValueMember of Combobox 5 19
As each individual will have his or her personal way of processing a concept and turning it into a reality, this is simply a record of my own system as a designer. It may feel daunting or even overwhelming when developing a new idea for a project…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The goal of the tutorial is to teach the user what exposure is and how to use the exposure slider. Analyze the photo that you want to edit, then adjust the exposure slider to your liking.
The goal of the tutorial is to teach the user how to import photos into Adobe Lightroom efficiently and to keep everything organized.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now