Frage

Im Folgenden finden Sie eine kubische Interpolation Funktion:

public float Smooth(float start, float end, float amount)
{
    // Clamp to 0-1;
    amount = (amount > 1f) ? 1f : amount;
    amount = (amount < 0f) ? 0f : amount;

    // Cubicly adjust the amount value.
    amount = (amount * amount) * (3f - (2f * amount));

    return (start + ((end - start) * amount));
}

Diese Funktion wird kubisch Interpolation zwischen dem Anfangs- und Endwert einen Betrag zwischen 0.0f gegeben - 1.0f. Wenn Sie diese Kurve zeichnen, würde man mit etwas am Ende wie folgt:

  

Abgelaufene Images Bild entfernt

Die kubische Funktion ist hier:

    amount = (amount * amount) * (3f - (2f * amount));

Wie stelle ich diese zwei Produkte Tangenten in produzieren und aus?

Zur Herstellung von Kurven wie folgt aus: (Linear zu kubischem Ende beginnen)

  

Abgelaufene Images Bild entfernt

Als eine Funktion

und wie diese als ein anderer: (Cubic Anfang bis Ende linear)

  

Abgelaufene Images Bild entfernt

got Wer irgendwelche Ideen? Vielen Dank im Voraus.

War es hilfreich?

Lösung

Was Sie wollen, ist ein Cubic Spline Hermite :

alt text

wobei p0 der Startpunkt ist, p1 der Endpunkt ist, ist m0 die Starttangente und m1 die Endtangente

Andere Tipps

Sie könnten eine lineare Interpolation und eine kubische Interpolation und Interpolation zwischen den beiden Interpolationsfunktionen.

dh.

cubic(t) = cubic interpolation
linear(t) = linear interpolation
cubic_to_linear(t) = linear(t)*t + cubic(t)*(1-t)
linear_to_cubic(t) = cubic(t)*t + linear(t)*(1-t)

wobei t im Bereich von 0 ... 1

Nun, ein einfacher Weg wäre dies:

-Expand your function by 2 x and y
-Move 1 to the left and 1 down
Example: f(x) = -2x³+3x²
g(x) = 2 * [-2((x-1)/2)³+3((x-1)/2)²] - 1

oder programmatisch (kubisch Stell):

double amountsub1div2 = (amount + 1) / 2;
amount = -4 * amountsub1div2 * amountsub1div2 * amountsub1div2 + 6 * amountsub1div2 * amountsub1div2 - 1;

Für die andere, einfach auslassen der „bewegte“:

g(x) = 2 * [-2(x/2)³+3(x/2)²]

oder programmatisch (kubisch Stell):

double amountdiv2 = amount / 2;
amount = -4 * amountdiv2 * amountdiv2 * amountdiv2 + 6 * amountdiv2 * amountdiv2;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top