Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - Implementing the Bentley-Ottmann algorithm -


i having trouble correctly implementing bentley-ottmann algorithm in c#. trying implement according pseudocode here. have posted main code below. assuming bst , priorityqueue classes implemented correctly, see problems code?

there no errors, not intersection points found, some. guess there's error in else part of code (when current event intersection point). i'm not sure pseudocode means swapping position of 2 segments in bst. way fine? because in end, 2 aren't swapped in bst. can't change positions either, because break bst properties.

also, right in assuming segments ordered in bst y-coordinate of left endpoint?

another error i've noticed can't seem able track down point (0, 0) gets eventlist. (0, 0) outputted geometry.intersects in case there no intersection, in case if conditions should stop getting added. have no idea how gets in. if print contents of eventlist after adding point in, (0, 0) never shows up. if print contents after extracting , popping element, (0, 0) shows up. have pop() method messing references, or problem in priorityqueue implementation?

if needed can show implementations bst , priority queue well.

static class bentleyottman {     private static void addintersectionevent(priorityqueue eventlist, segment segev, segment sega, segpoint i)     {         i.intersectingsegments = new tuple<segment, segment>(segev, sega);         i.type = segmentpointtype.intersectionpoint;          eventlist.add(i);     }      public static void solve(panel surface, textbox debug)     {         debug.clear();         var seglist = generator.seglist;          priorityqueue eventlist = new priorityqueue();          foreach (segment s in seglist)         {             eventlist.add(new segpoint(s.a, s, segmentpointtype.leftendpoint));             eventlist.add(new segpoint(s.b, s, segmentpointtype.rightendpoint));         }          bst sweepline = new bst();         while (!eventlist.empty)         {             segpoint ev = eventlist.top();              eventlist.pop();              if (ev.type == segmentpointtype.leftendpoint)             {                 segment segev = ev.segment;                 sweepline.insert(segev);                  segment sega = sweepline.inorderpre(segev);                 segment segb = sweepline.inordersuc(segev);                  segpoint = new segpoint();                 if (sega != null && geometry.intersects(segev, sega, out i.point))                 {                     addintersectionevent(eventlist, sega, segev, i);                 }                 if (segb != null && geometry.intersects(segev, segb, out i.point))                 {                     addintersectionevent(eventlist, segev, segb, i);                 }             }             else if (ev.type == segmentpointtype.rightendpoint)             {                 segment segev = ev.segment;                  segment sega = sweepline.inorderpre(segev);                 segment segb = sweepline.inordersuc(segev);                  sweepline.remove(segev);                  segpoint = new segpoint();                 if (sega != null && segb != null && geometry.intersects(sega, segb, out i.point))                 {                     addintersectionevent(eventlist, sega, segb, i);                 }             }             else             {                 generator.drawpoint(ev.point, surface, brushes.red);                  segment seg1 = ev.intersectingsegments.item1;                 segment seg2 = ev.intersectingsegments.item2;                  sweepline.remove(seg1);                 sweepline.remove(seg2);                  segment t = new segment(seg1);                 seg1 = new segment(seg2);                 seg2 = new segment(t);                  sweepline.insert(seg1);                 sweepline.insert(seg2);                  segment sega = sweepline.inorderpre(seg2);                 segment segb = sweepline.inordersuc(seg1);                  segpoint = new segpoint();                 if (sega != null && geometry.intersects(seg2, sega, out i.point))                     addintersectionevent(eventlist, sega, seg2, i);                 if (segb != null && geometry.intersects(seg1, segb, out i.point))                     addintersectionevent(eventlist, seg1, segb, i);             }         }     } } 

i cannot understand code without idea of other classes do, can answer of other questions.

the segments ordered in bst y coordinate of intersection sweep line. when encounter left endpoint add segment tree using y coordinate of left endpoint of entering segment (comparing y coordinate of intersection of other segment sweep line). when encounter right endpoint remove segment tree. when encounter intersection, order of intersections of 2 segments sweep line switches, swap 2 segments in tree. example consider 2 segments

 = {(-1,1),(1,-1)} ,  b = {(-1,-1),(1,1)} 

when x coordinate of sweep line less 0 intersection of segment sweep line greater intersection of segment b sweep line. , if sweep line greater 0 reverse true. (draw picture.)

it instructive draw simple example, , trace going on step step, drawing sweep line each event , labeling segments in columns between events, keeping track of bst , verifying bst keeps same order segments in region valid. (i'm sorry if not clear be.)

note: assumes segments in "general position", i.e. no segment vertical, no more 2 segments intersect @ given point, etc. dealing segments not in general position outlined on wikipedia page


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -