Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   How to redistribute points on line..?? (http://www.go4expert.com/forums/redistribute-line-t18929/)

rakeshthp 8Aug2009 14:11

How to redistribute points on line..??
 
1 Attachment(s)
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..??

Thanks in advance

xpi0t0s 9Aug2009 01:55

Re: How to redistribute points on line..??
 
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?


rakeshthp 9Aug2009 18:20

Re: How to redistribute points on line..??
 
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 ...

Quote:

Convert the vertex near the number 1 to an r theta offset from the neighbouring node,
how to find theta..??

Quote:

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.:
In this case the vertex closest to P can be slightly adjusted so that old P will coincide with new vertex..

Thanks n regards

xpi0t0s 9Aug2009 23:41

Re: How to redistribute points on line..??
 
> how to find theta..??

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

rakeshthp 11Aug2009 10:34

Re: How to redistribute points on line..??
 
Hi...

Thanks yaar.. It worked absolutely fine.. Check out for my new post..

Thanks and regards


All times are GMT +5.5. The time now is 01:28.