Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 19th, 2006, 05:42 PM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dataview bug? or code error..



Hi all,
I'm trying to compute a convex hull from a set of points using Jarvis' March. As part of the algorithm I'm computing for each point, its angle in relation to the other points. I compute this information in the datatable and then sort it using a dataview. Sometimes the dataview sorts correctly, sometimes it .. doesn't? I'll find most of the rows sorted correctly according to angle, but maybe three rows in strange places. This throws off the whole algorithm obviously. Anyone know what's going on? I appreciate any help at all.

Code:
            do
            {
                for (i = 0; i < dv.Count; i++)
                {
                    if(m_dt2.Rows.Count < 2)
                        dv[i][2] = getAngle(basePoint.X, basePoint.Y, Convert.ToInt32(dv[i][0].ToString()), Convert.ToInt32(dv[i][1].ToString()));
                    else
                    {
                        a = new Point(Convert.ToInt16(m_dt2.Rows[m_dt2.Rows.Count-2][0]), Convert.ToInt16(m_dt2.Rows[m_dt2.Rows.Count-2][1]));
                        b = new Point(Convert.ToInt16(m_dt2.Rows[m_dt2.Rows.Count-1][0]), Convert.ToInt16(m_dt2.Rows[m_dt2.Rows.Count-1][1]));
                        c = new Point(Convert.ToInt16(dv[i][0].ToString()), Convert.ToInt16(dv[i][1].ToString()));
                        ab = Math.Sqrt(((b.X - a.X)*(b.X - a.X)) + ((b.Y - a.Y)*(b.Y - a.Y)));
                        bc = Math.Sqrt(((c.X - b.X)*(c.X - b.X)) + ((c.Y - b.Y)*(c.Y - b.Y)));
                        ac = Math.Sqrt(((c.X - a.X)*(c.X - a.X)) + ((c.Y - a.Y)*(c.Y - a.Y)));
                        dv[i][2] = Convert.ToDouble(Math.Acos((ab*ab+bc*bc-ac*ac)/(2*ab*bc)));
                    }
                }

                if(m_dt2.Rows.Count < 2)
                    dv.Sort = "angle ASC";
                else
                    dv.Sort = "angle DESC";
                dgPoints.DataSource = dv;
                Push(Convert.ToInt32(dv[0][0].ToString()), Convert.ToInt32(dv[0][1].ToString()));
                basePoint = new Point(Convert.ToInt32(dv[0][0].ToString()),Convert.ToInt32(dv[0][1].ToString()));
                dv[0].Delete();
            }while(basePoint.X != baseX && basePoint.Y != baseY);


Reply With Quote
  #2 (permalink)  
Old November 20th, 2006, 03:03 PM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Fixed. The problem was that I was rebinding the dataview to the datagrid during each iteration. For some reason this was giving a wacky sort order.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a big bug on a code busteronline ASP.NET 1.0 and 1.1 Basics 0 September 15th, 2008 09:11 AM
Forum Caching Bug in VB Code Scott663 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 March 27th, 2008 08:24 PM
Bug in the Poll VB code? thuyvncr BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 April 21st, 2007 08:43 PM
Is this code correct for a Dataview rayncarnation ASP.NET 1.0 and 1.1 Basics 0 November 7th, 2005 05:55 PM
Variable value error / bug ? James Diamond Pro VB 6 5 May 24th, 2004 08:49 AM



All times are GMT -4. The time now is 11:34 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.