Click here to Skip to main content
15,889,852 members
Please Sign up or sign in to vote.
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 6-Dec-11 23:29pm
v2

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.
 
Share this answer
 
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
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.
 
Share this answer
 
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)



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