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. General Programming
  3. C#
  4. How to decide if a Point is on a curve

How to decide if a Point is on a curve

Scheduled Pinned Locked Moved C#
tutorialquestion
6 Posts 3 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.
  • T Offline
    T Offline
    TaoLi
    wrote on last edited by
    #1

    I draw a curve using the DrawCurve method. I also want to have some kind of interaction with the curve when moving the mouse over it. Could someone show me how to decide if a Point is on the curve? Thanks!

    N 1 Reply Last reply
    0
    • T TaoLi

      I draw a curve using the DrawCurve method. I also want to have some kind of interaction with the curve when moving the mouse over it. Could someone show me how to decide if a Point is on the curve? Thanks!

      N Offline
      N Offline
      Nathan Blomquist
      wrote on last edited by
      #2

      Hello, The way I have seen this done was in a project I worked on in a group for school. Check out the Region and GraphicsPath classes. Region is found in System.Drawing and GraphicsPath is in System.Drawing.Drawing2D. 1. DrawCurve to screen 2. Create a GraphicsPath and draw to it. 3. Create a Region from the GraphicsPath. 4. Invoke IsVisible( somePoint ) on the Region. In this case somePoint would be your mouse point. Hope this helps, Nathan --------------------------- Hmmm... what's a signature?

      T 2 Replies Last reply
      0
      • N Nathan Blomquist

        Hello, The way I have seen this done was in a project I worked on in a group for school. Check out the Region and GraphicsPath classes. Region is found in System.Drawing and GraphicsPath is in System.Drawing.Drawing2D. 1. DrawCurve to screen 2. Create a GraphicsPath and draw to it. 3. Create a Region from the GraphicsPath. 4. Invoke IsVisible( somePoint ) on the Region. In this case somePoint would be your mouse point. Hope this helps, Nathan --------------------------- Hmmm... what's a signature?

        T Offline
        T Offline
        TaoLi
        wrote on last edited by
        #3

        Thanks a lot!

        1 Reply Last reply
        0
        • N Nathan Blomquist

          Hello, The way I have seen this done was in a project I worked on in a group for school. Check out the Region and GraphicsPath classes. Region is found in System.Drawing and GraphicsPath is in System.Drawing.Drawing2D. 1. DrawCurve to screen 2. Create a GraphicsPath and draw to it. 3. Create a Region from the GraphicsPath. 4. Invoke IsVisible( somePoint ) on the Region. In this case somePoint would be your mouse point. Hope this helps, Nathan --------------------------- Hmmm... what's a signature?

          T Offline
          T Offline
          TaoLi
          wrote on last edited by
          #4

          There is a problem with this method. Though the curve is a open end curve, the region seems like a closed region. IsVisible returns true not only when the mouse is over the curve but also inside the region enveloped by the region. Have you encountered the same problem? How did you resolve it? Thanks!

          N A 2 Replies Last reply
          0
          • T TaoLi

            There is a problem with this method. Though the curve is a open end curve, the region seems like a closed region. IsVisible returns true not only when the mouse is over the curve but also inside the region enveloped by the region. Have you encountered the same problem? How did you resolve it? Thanks!

            N Offline
            N Offline
            Nathan Blomquist
            wrote on last edited by
            #5

            Hmmm.... I don't know how to fix that problem right off had. You will have to look through the documentation some more. I am sorry that this did not solve the problem exactly. Please post here again if you find a solution. Sorry, Nathan --------------------------- Hmmm... what's a signature?

            1 Reply Last reply
            0
            • T TaoLi

              There is a problem with this method. Though the curve is a open end curve, the region seems like a closed region. IsVisible returns true not only when the mouse is over the curve but also inside the region enveloped by the region. Have you encountered the same problem? How did you resolve it? Thanks!

              A Offline
              A Offline
              adelboy
              wrote on last edited by
              #6

              I found the same problem as above and your description of the problem helped to give me the answer. If the path is closed already, the path.IsVisible(point) should work. To keep the line as pure looking as possible using pixels, just reverse the points in the array and add them to the original set. Then add them to a closed curve in the path. GraphicsPath _curvePath = new GraphicsPath(); List<PointF> closedCurvePoints = new List<PointF>(_curvePoints); closedCurvePoints.Reverse(); closedCurvePoints.AddRange(_curvePoints); _curvePath.AddClosedCurve(closedCurvePoints.ToArray()); This worked well for me - even for curves that backed in on themselves. Hopefully it will be helpful to someone else if you have no need for this info anymore

              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