Click here to Skip to main content
15,892,059 members
Home / Discussions / C#
   

C#

 
Questionget my IP Pin
Green Fuze13-Sep-06 5:00
Green Fuze13-Sep-06 5:00 
AnswerRe: get my IP Pin
Obaid ur Rehman13-Sep-06 5:44
Obaid ur Rehman13-Sep-06 5:44 
GeneralRe: get my IP Pin
Green Fuze13-Sep-06 5:59
Green Fuze13-Sep-06 5:59 
GeneralRe: get my IP Pin
User 665813-Sep-06 6:15
User 665813-Sep-06 6:15 
QuestionUninstall using command prompt Pin
kulile13-Sep-06 4:57
kulile13-Sep-06 4:57 
QuestionMessageBox Text Pin
numbers1thru913-Sep-06 4:43
numbers1thru913-Sep-06 4:43 
AnswerRe: MessageBox Text Pin
Glen Harvy13-Sep-06 4:59
Glen Harvy13-Sep-06 4:59 
QuestionCan a Math genius please help me!? [modified] Pin
srev13-Sep-06 4:26
srev13-Sep-06 4:26 
Hi Guys,

I’m creating an animation program and have built a Bezier spline motion editor. The user-controllable curve plots time(x) against value(y). So my challenge is to retrieve the 'y' value from a given 'x' on the curve. However, all the articles I've been able to find/understand only give a formula for calculating an x or y from 't' - the percentage along the given cubic bezier curve.

As 't' is more concentrated around areas which heavily curve (to make a smooth curve), it's not possible to calculate y from x. So I'm using what seems to be a recognised work around and iteratively guessing at which 't' value produces x, continually reducing the difference until I find the correct 't' which produces my required x. I then use this 't' to calculate y.

This all works perfectly well. However, this is an animation program so I need to optimize this process. My current technique requires up to 15 iterations before it finds an accurate value for 't'. I found an article online by Don Lanaster, “Some more cubic spline math BEZMATH.PS”. He mentions using the Newton-Raphelson method to reduce this process down to 3 iterations. Apparently this technique uses the slope of the curve to make the approximation of 't' more accurate. However, the formula he uses doesn't match the formula I currently have working to calculate a value on the curve. I'm sure I'm misunderstanding it!

At this point I have to confess I am a Math dummy. I can work my way around practical mathematical issues as long as I don’t have to resort to long formulas full of ancient Greek!

Here's an extract from Don's article:

--- Quote ----
Let's use a better ploy to get our approximation to close quickly. It is called the NEWTON-RAPHELSON method, but is much simpler than it sounds. Say we get an error of x - x1. x1 is the current x for our current guess. At x1, our spline curve has a slope. Find the slope.

The slope is expressed as rise/run. Now, on any triangle...

rise = run x (rise/run)

This gives us a very good improvement for our next approximation. It turns out that the "adjust for slope" method converges very rapidly. Three passes are usually good enough. If our curve has an equation of...

x = At^3 + Bt^2 + Ct + D

...its slope will be...

x' = 3At^2 +2Bt + C

And the dt/dx slope will be its inverse or 1/(3At^2 + 2Bt +C). This is easily calculated. The next guess will be...

nextguess = currentt + (curentx - x)(currentslope)

----- end quote ----



So here's the function I call iteratively with varying values for 't' and it returns 'x' for me to compare with what I want:

public float CalcBezierValue(float t, float A, float B, float C, float D)
{
t = 1 - t; // Reverse the normalised percentage

float F1 = t * t * t; // These vars used purely for visual clarity
float F2 = 3 * t * t * (1 - t);
float F3 = 3 * P * (1 - t) * (1 - t);
float F4 = (1 - t) * (1 - t) * (1 - t);

return A * F1 + B * F2 + C * F3 + D * F4;
}

As you can see the base formula which produces the return value is quite different from the one in the article (x = At^3 + Bt^2 + Ct + D). Consequently I’m failing to comprehend how to calculate the slope value or its inverse which seem to be required to reduce the number of calls to this function.

Can anyone help me?

Many thanks for your time,

Simon


-- modified at 12:02 Wednesday 13th September, 2006
AnswerRe: Can a Math genius please help me!? Pin
papa8013-Sep-06 5:40
papa8013-Sep-06 5:40 
GeneralRe: Can a Math genius please help me!? Pin
srev13-Sep-06 6:21
srev13-Sep-06 6:21 
AnswerRe: Can a Math genius please help me!? Pin
Guffa13-Sep-06 6:49
Guffa13-Sep-06 6:49 
AnswerRe: Can a Math genius please help me!? Pin
Ed.Poore13-Sep-06 6:50
Ed.Poore13-Sep-06 6:50 
GeneralRe: Can a Math genius please help me!? Pin
srev13-Sep-06 23:43
srev13-Sep-06 23:43 
Questionwant to implement zoom operations in C# Pin
kalaveer13-Sep-06 4:23
kalaveer13-Sep-06 4:23 
AnswerRe: want to implement zoom operations in C# Pin
Nader Elshehabi13-Sep-06 7:36
Nader Elshehabi13-Sep-06 7:36 
GeneralRe: want to implement zoom operations in C# Pin
kalaveer13-Sep-06 19:11
kalaveer13-Sep-06 19:11 
GeneralRe: want to implement zoom operations in C# Pin
Nader Elshehabi14-Sep-06 1:40
Nader Elshehabi14-Sep-06 1:40 
QuestiontreeView1 = treeView2 ??? Pin
i-p-g-i13-Sep-06 4:19
i-p-g-i13-Sep-06 4:19 
AnswerRe: treeView1 = treeView2 ??? Pin
albCode13-Sep-06 4:32
albCode13-Sep-06 4:32 
GeneralRe: treeView1 = treeView2 ??? Pin
i-p-g-i13-Sep-06 4:46
i-p-g-i13-Sep-06 4:46 
GeneralRe: treeView1 = treeView2 ??? Pin
albCode13-Sep-06 4:52
albCode13-Sep-06 4:52 
GeneralRe: treeView1 = treeView2 ??? Pin
i-p-g-i13-Sep-06 5:19
i-p-g-i13-Sep-06 5:19 
GeneralRe: treeView1 = treeView2 ??? Pin
albCode13-Sep-06 5:29
albCode13-Sep-06 5:29 
QuestionRight Click File Handling Program Pin
shultas13-Sep-06 4:11
shultas13-Sep-06 4:11 
AnswerRe: Right Click File Handling Program Pin
led mike13-Sep-06 4:40
led mike13-Sep-06 4:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.