# How to redistribute points on line..??

Discussion in 'C' started by rakeshthp, Aug 8, 2009.

1. ### rakeshthpNew Member

Joined:
Aug 8, 2009
Messages:
7
0
Trophy Points:
0
hello,

I dont know actually in which category this problem fits into.. i assumed this is the correct place.. If not then pls guide me as where to post it..

I have set of points which are connected with a line... This connected line may or may not be straight.. As we all know the first and last points of this connected line is called nodes.. and intermediate points are known as vertices.. Now, i need to redistribute the vertices over this line in such a way that, all the vertices are equally spaced.

I mean, suppose if the user wants the vertices to be redistributed with the spacing of say 10 units.. Here i need to have new set of vertices, having distance between each pair of points(x,y) should be 10.

One way i tried this is to start with the first point of the connected lines, and read each point(x,y) along the line segment and find whether the distance of these two points is 10. If it is 10, then take the new point as your reference point and repeat the process... This method works fine. But for lines of different directions, the distance is not same.. so i dont get equally spaced points. The problem is diagramatically expained in the file attached.. 1 is the first input from the user.. 2 is after redistributing...

I just want to calculate new points... not to plot them..

Is there any other way out for this..??

File size:
5.2 KB
Views:
72
2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
What if the spacing means the end points can't be included? For example, if we want vertices spread over every 4 units in a 10 unit line, this isn't possible:
Code:
```x--------x
x---x---x- ?
```
But anyway I think you could use polar notation to solve this. Convert the vertex near the number 1 to an r theta offset from the neighbouring node, then where n=the number of points desired, divide r by n-1 and that gives you the distance between each point, then use that to calculate the r theta position of each new vertex and convert each back to rectangular to get the x,y positions.

So let's say for example vertex 1 is at r theta = 12 at 45 degrees, the neighbouring node is at (0,0), and we want 4 points. 12/3=4 so the new vertices will be at r=0, 4, 8 and 12; theta will be the same for all, so just convert (0,45), (4,45), (8,45) and (12,45) back to rectangular coords and that will be the solution.

But if you know the spacing then the division isn't necessary; you still need theta so the r-p and p-r conversions are still both needed, but if vertex 1 isn't at an r that is evenly divisible by the spacing then you have the previously mentioned problem, what if, say, vertex 1 is at (11,45) and the spacing of 4 is requested? Would you then place the next vertex at r=1 for the next segment, i.e.:
Code:
```N--------V--------V---..   // Original lines.  V=vertex, N=node
N---x---xP--x---x-P-x-..   // New lines with x at the new vertices.  What happens at P?
```

3. ### rakeshthpNew Member

Joined:
Aug 8, 2009
Messages:
7
0
Trophy Points:
0
HI..

Dividing into n number of points is another alternative option.. I mean user can redistribute vertices either by specifying spaces of by specifying number of points.. Anyhow, i need that also later. Thanks in advance ...

how to find theta..??

In this case the vertex closest to P can be slightly adjusted so that old P will coincide with new vertex..

Thanks n regards

4. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
> how to find theta..??

I already said. Look up "rectangular to polar conversion" in your favourite search engine.

Joined:
Aug 8, 2009
Messages:
7