Move Point along multiple lines

  • Context: Undergrad 
  • Thread starter Thread starter Zoltan
  • Start date Start date
  • Tags Tags
    Lines Multiple Point
Click For Summary
SUMMARY

The discussion revolves around moving a point along multiple line segments, specifically triangles or rectangles, using a parameterized approach. The original method used a fixed increment for movement, which resulted in inconsistent speeds across lines of varying lengths. The solution proposed involves recalibrating the parameter 'p' based on the lengths of the segments, ensuring uniform speed regardless of line length. The final approach calculates the adjusted parameter for each segment to maintain consistent movement across the entire shape.

PREREQUISITES
  • Understanding of parameterized equations for line movement
  • Familiarity with basic geometry, specifically triangles and rectangles
  • Knowledge of programming concepts, particularly loops and conditional statements
  • Experience with mathematical functions such as square root and division
NEXT STEPS
  • Implement the proposed algorithm in a programming language of choice
  • Explore optimization techniques for real-time point movement in graphics
  • Study interpolation methods for smoother transitions along line segments
  • Investigate collision detection algorithms for dynamic shapes
USEFUL FOR

Game developers, graphics programmers, and anyone involved in computational geometry or animation who needs to implement smooth point movement along complex paths.

Zoltan
Messages
6
Reaction score
0
Hi, i got problem i am trying to solve.

basically i got point moving along bunch of lines ( either rectangles/triangles it is custom, generated in code ).

I am using this equation to find out x,y coordinates for moving along specific line :
(its taken from code )

x = x1 + center.x + (x2 - x1) * p
y = y1 + center.y + (y2 - y1) * p

center is there just to adjust the whole shape
p is basically the increment for moving the point on the line.

Now i got logic to move between the different lines, by just figuring out if the p is over 1 switch to next line. Thats all fine and dandy.

But here comes the problem. Each of the p increments are same each frame, i.e. 0.1,0.2,0.3,0.4 it means that no matter how long the line is it always takes same amount of time to finish. Because 0.1 distance represents 10% of length of the line, it would move 10% of the line distance.

Now i can fix this with just dividing the p basically by the length of the line, thus all the movement on all lines is same. If you would have triangle with two really long lines and one really small. You would have really fast movement on the two long lines and really slow movement on the small with the 10% movement per frame. But that's what i don't want :) I want the speed to be same on each of the line while mainting same amount of time it took to finish movement on whole shape before normalising it.

I do that by dividing the increment by the line distance, its working fine, but the speed is mush slower obviously. ( Example, if you would have increment 1 unit per frame and length of line was 10 units, speed would be 0.1, but problem is you got 3 different lines and the speed needs to adjusted so that it takes same amount of time as before this length division )

I tried things like take circumference of the whole shape, dividing it by amount of sides and using it that value to multiple the speed. Wrong

I tried this equation when the shape was triangle :
(x/a + x/b +x/c) * y = 3x
x = increment
y = desired multiplication of the speed

it basically says if u have 3 frames movement, one at each of the side of the triangle with the normalised increment, if you mulitple that by some value, you get equal amount to original increments in 3 frames 1 = 1. Wrong ! value doesn't work

So, i am not sure if its clear or not :) I am not too good in explaining stuff. But if you can help me with the problem in any way, i would very very grateful. Any suggestions welcomed. Thank you for your time taken to read it all this.

Zoltan

Edit:

I realized i probably should have factor how long the point is on each of the line so i adjusted the equation like this:

((x/a * a/t) + (x/b * b/t) + (x/c * c/t)) * y = x

t = circumference of the shape (triangle)

Still not working tho.
 
Last edited:
Mathematics news on Phys.org
There may be much better ways of doing this, but here's what I would do.

First, I would treat p as being the parameter over the whole path (i.e. p=0 means that the point is at the beginning of the first line, and p=1 means that the point is at the end of the last line). Then I would work out the values for p at which the point is at the intersection of two lines--i.e. when it switches lines. For example, suppose you had the triangle case, so there are three lines. Let their lengths be called L1, L2, L3. Then p switches from the first line to the second line at p1 = L1 / (L1+L2+L3), and from the second to the third line at p2 = (L1+L2) / (L1+L2+L3).

Now as p changes incrementally from 0 to 1, figure out which line segment it should be on by comparing it to p1 and p2, and use that line segment's values of x1, x2, y1, y2 in your calculation of the point's coordinates. Because now the limits of p for each line are different, you'll have to "recalculate" p so that it represents how far along just that line segment it is. I think you'll understand what I mean when you see the "code" below.

So, here is my "code", untested and unimplemented. Hope it's useful to you.

Code:
// Given vertices (x1,y1), (x2,y2), (x3,y3), (x4,y4), representing three line segments
// from points 1 --> 2, 2 -->3, 3-->4.

L1 = sqrt((x2-x1)^2+(y2-y1)^2)
L2 = sqrt((x3-x2)^2+(y3-y2)^2)
L3 = sqrt((x4-x3)^2+(y4-y3)^2)

L = L1+L2+L3

p0 = 0
p1 = L1/L
p2 = (L1+L2)/L
p3 = 1

for loop: p from p0 to p3 (or 0 to 1) with whatever increment you want
  if p0 <= p < p1:
    p_lo = p0
    p_hi = p1
    x_lo = x0
    x_hi = x1
    y_lo = y0
    y_hi = y1
  else if p1 <= p < p2:
    etc. // same as above but altered accordingly
  else if p2 <= p <= p3:
    etc.
  end if

  p_adj = (p - p_lo) / (p_hi - p_lo)  // So now p_adj is an 'adjusted' p that ranges from 0 to 1
                                      // according to how far along this line segment is has progressed

  x = x_lo + center.x + (x_hi - x_lo) * p_adj
  y = y_lo + center.y + (y_hi - y_lo) * p_adj

  // Display point, or whatever you want to do with it...

end for loop
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K