15,847,583 members
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 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.

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

## 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