Pages: « 1 2
  Print  
Author Topic: Path trouble  (Read 3720 times)
Offline (Male) polygone
Reply #15 Posted on: May 25, 2012, 07:03:00 PM

Contributor
Location: England
Joined: Mar 2009
Posts: 803

View Profile
I suddenly thought of a way to do this, right after I switch methods for what I needed doing so I don't need it any more. It should have been obvious to me near the start as well .

If you use a quadratic bezier for the path instead, then alter the value of t for smooth paths so it runs against it linearly. I have tested the values in a spreadsheet which I wrote before and it works perfectly.

You have:  D = 2(1-t)t*Q + tt*R

Where D is the distance it should be moving linearly calculated, which in the script is the value of (position - ppi->position)*total_length. Q is the length of 2nd-path point to the 1st one and R is the length of the 3rd-path point to the 1st one. Then that can be rearranged using the quadratic formula to:

t = (-2Q + SQRT((4QQ + 4D(R – 2Q))) / (2(R – 2Q))     //You have to check for 2(R – 2Q) = 0 also, in which case set t to 0.5

Then just use that value for t with a regular quadratic bezier equation to calculate the x/y positions and it will work correctly linearly as well as curving correctly. But to be honest I really can't actually be fucked programming this, maybe in a month or something lol. I really don't need it any more myself so until maybe it's an issue for someone else I can't be bothered doing it.
« Last Edit: May 25, 2012, 07:16:40 PM by polygone » Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Pages: « 1 2
  Print