Click here to Skip to main content
13,143,637 members (30,070 online)
Click here to Skip to main content
Add your own
alternative version


16 bookmarked
Posted 5 Jun 2007

Line to Region

, 19 Jun 2007
Rate this:
Please Sign up or sign in to vote.
This class gets an array of pointf() and returns the corresponding line region with custom width.


Last summer when I was I trying to a write a chart control for my software, I noticed that my program could not distinguish between chart lines and shapes and I had to make Auto-Info on the plot which got activated when the mouse moved on the objects. I made a class that gets the line points in an array of type Pointf and returns the corresponding Region with the custom width. This was helpful and that's why now I can make a UserControl or Control with all the ordinary events such as MouseMove, MouseClick, and etc., and set its region to my custom region and add it to my project as a scatter plot. The mathematical theory is simple. Suppose that we have three points A, B, and C in an array of Pointf.

Screenshot - untitled.jpg

Here is the procedure that makes the region:

  1. The slope of the bisector of angle β is calculated.
  2. Two points on the bisector with equal distance to B are determined (couple points).
  3. For all real points, we make these two points.
  4. The position of each couple will be verified according to the closer couples.
  5. Two arrays of points in two sides will be generated.
  6. Two arrays will join together and generate the region.

Using the code

To use this class, just instantiate it and call the FTR function and supply the parameters.

In the example file, an array of sin(x) is generated and then it is passed to the function to retrieve the region (some parts of code are omitted here).

Dim FTR As New FunctionToRegion.FunctionToRegion
Dim pnt(500) As PointF 
For i As Double = 0 To 500
       pnt(i).X = i
       pnt(i).Y = 110 + 100 * Math.Sin(i / 50)
Region = FTR.FTR(pnt, 4)



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Amir Emamjomeh
United Kingdom United Kingdom
Amir Emamjomeh is a senior petroleum reservoir engineer and also programmer who has been involved in several industrial and research projects proposed by the petroleum industry of Iran since 2006. His programming experiences include C, C++, C# , VB.Net, MATLAB and Visual FORTRAN.

You may also be interested in...

Comments and Discussions

General5+ Pin
Southmountain11-Oct-13 13:33
memberSouthmountain11-Oct-13 13:33 
GeneralMy vote of 5 Pin
manoj kumar choubey28-Feb-12 19:23
membermanoj kumar choubey28-Feb-12 19:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 20 Jun 2007
Article Copyright 2007 by Amir Emamjomeh
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid