15,795,712 members
0.00/5 (No votes)
See more:
Hi all,

I have a list of points created during design time. when I run my program a shape is created according to the order in which the points have been added. When I then click on the shape , a new point is created according to the position of the mouse relative to the drawing area in my application. My problem is , my list is already in a specific order and I am having trouble figuring out a proper method to work out if the new point is before or after the current point already drawn on the shape.

Here is an illustration of my problem

This is the Shape ive drawn when the app starts:
``` 150,150
270, 150
270, 270
150, 270
150, 150

150,150  o-----------o 270, 150
|           |
|           |
|           |
150, 270 o-----------o 270, 270```

And this is what I want to do
``` 150,150
270, 150
270, 270
265 ,270  #inserted here dynamically
150, 270
150, 150

150,150  o-----------o 270, 150
|           |
|           |
|           |
150, 270 o-----o-----o 270, 270
265,270```
Posted
Updated 7-Dec-11 0:29am
v2

## Solution 1

What do you want to do if the new point is inside the shape? Imagine the new point is at the center of a square or rectangle.

v2
Comments
HappyMan811 8-Dec-11 9:58am
I would like to click and drag on that point in result changing the shape. But I have already worked out that part of the problem

## Solution 2

At first, determine which are the two closest points , if there is not clear which are the two closests points (by exemple, the distants are not very different) you must move your point. You can calculate the distance using the formula distance = (xp - xn)^2 + (yp - yn)^2 for each 1 to n points in the ordered shape (you do not need the square root). Finally you insert your point between the two closests points in the ordered points set.

Comments
HappyMan811 9-Dec-11 3:13am
Many thanks

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

Top Experts
Last 24hrsThis month
 Richard Deeming 120 Dave Kreskowiak 100 Andre Oosthuizen 60 CHill60 50 Maciej Los 40
 Andre Oosthuizen 300 Rick York 170 Dave Kreskowiak 145 Richard Deeming 110 Maciej Los 105

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900