Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. IT & Infrastructure
  4. line drawing algorithm

line drawing algorithm

Scheduled Pinned Locked Moved IT & Infrastructure
csscomgraphicsalgorithmshelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pathi
    wrote on last edited by
    #1

    hi I want to find whether the mouse is positioned on the line which I draw ,or not.for this I am using Bresenhalm algorithm.this is the code. /* [helpstring] */ STDMETHODIMP CConnector::intersects(/* [in] */ SPoint pt,/* [retval][out] */ BOOL __RPC_FAR *checkflag) { SRect boundingRect; ptrConState->get_Position(&boundingRect); SPoint start,end; start.x=boundingRect.topLeft.x; start.y=boundingRect.topLeft.y; end.x=boundingRect.bottomRight.x; end.y=boundingRect.bottomRight.y; double m=findSlope(start,end); int dx,dy,xend,yend,p,x1,y1; dx=abs(start.x-end.x); dy=abs(start.y-end.y); //if(m<1||m>-1) if(m<=1&&m>=0) { p=2*dy-dx; if(start.x>end.x) { x1=end.x; y1=end.y; xend=start.x; } else { x1=start.x; y1=start.y; xend=end.x; } while(x1=0) y1=y1+1; //else // y1=y1-1; p=p+2*(dy-dx); } if((pt.x==x1)&&(pt.y==y1)) { *checkflag=1; return S_OK; } } *checkflag=0; return S_OK; } else if(m<0&&m>-1) { p=2*dy-dx; if(start.x>end.x) { x1=end.x; y1=end.y; xend=start.x; } else { x1=start.x; y1=start.y; xend=end.x; } while(x1=1) { p=2*dx-dy; if(start.y>end.y) { x1=end.x; y1=end.y; yend=start.y; } else { x1=start.x; y1=start.y; yend=end.y; } while(y11) x1=x1+1; else x1=x1-1; p=p+2*(dx-dy); } if((pt.x==x1)&&(pt.y==y1)) { *checkflag=1; return S_OK; } } *checkflag=0; return S_OK; } *checkflag=0; return S_OK; } here the problem is i am not getting exact intersections for the lines slope of which is less than 0 and greater than -1.why this problem? please find any mistakes and hellp me.I also want that the user of my application can easily select the lines provided some offset for the line to get selected. Thanks regards Pathi bhikshapathi_g@semanticspace.com

    M 1 Reply Last reply
    0
    • P pathi

      hi I want to find whether the mouse is positioned on the line which I draw ,or not.for this I am using Bresenhalm algorithm.this is the code. /* [helpstring] */ STDMETHODIMP CConnector::intersects(/* [in] */ SPoint pt,/* [retval][out] */ BOOL __RPC_FAR *checkflag) { SRect boundingRect; ptrConState->get_Position(&boundingRect); SPoint start,end; start.x=boundingRect.topLeft.x; start.y=boundingRect.topLeft.y; end.x=boundingRect.bottomRight.x; end.y=boundingRect.bottomRight.y; double m=findSlope(start,end); int dx,dy,xend,yend,p,x1,y1; dx=abs(start.x-end.x); dy=abs(start.y-end.y); //if(m<1||m>-1) if(m<=1&&m>=0) { p=2*dy-dx; if(start.x>end.x) { x1=end.x; y1=end.y; xend=start.x; } else { x1=start.x; y1=start.y; xend=end.x; } while(x1=0) y1=y1+1; //else // y1=y1-1; p=p+2*(dy-dx); } if((pt.x==x1)&&(pt.y==y1)) { *checkflag=1; return S_OK; } } *checkflag=0; return S_OK; } else if(m<0&&m>-1) { p=2*dy-dx; if(start.x>end.x) { x1=end.x; y1=end.y; xend=start.x; } else { x1=start.x; y1=start.y; xend=end.x; } while(x1=1) { p=2*dx-dy; if(start.y>end.y) { x1=end.x; y1=end.y; yend=start.y; } else { x1=start.x; y1=start.y; yend=end.y; } while(y11) x1=x1+1; else x1=x1-1; p=p+2*(dx-dy); } if((pt.x==x1)&&(pt.y==y1)) { *checkflag=1; return S_OK; } } *checkflag=0; return S_OK; } *checkflag=0; return S_OK; } here the problem is i am not getting exact intersections for the lines slope of which is less than 0 and greater than -1.why this problem? please find any mistakes and hellp me.I also want that the user of my application can easily select the lines provided some offset for the line to get selected. Thanks regards Pathi bhikshapathi_g@semanticspace.com

      M Offline
      M Offline
      moriarty
      wrote on last edited by
      #2

      See pg. 267 of the Win2K Graphics API Black Book. Unfortunately the snippet isn't on the CD, and I don't feel like taking the time to type it in here, but it is a better solution. Dave R

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups