Wie erstelle ich eine glatte Bezier -Kurve?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie erstelle ich eine glatte Bezier -Kurve?

Post by Anonymous »

Ich habe die Bezier -Kurve in Openentk erstellt. Ich erhalte ein Ergebnis, aber wie Sie sehen können, dass sie nicht glatt und regelmäßig ist. Ich weiß immer noch nicht, wie es glatt wird. Onload < /p>

Code: Select all

float[] Vertices =
{
-1.0f,  0.0f,
0.0f,  1.0f,
1.0f,  0.0f,
};

InterpolatedVertices = Interpolation.Quadratic(
(Vertices[0], Vertices[1]),
(Vertices[2], Vertices[3]),
(Vertices[4], Vertices[5]),
1000,
0.01f
);
< /code>
Dies ist der Code zum Zeichnen < /p>
GL.DrawArrays(PrimitiveType.Points, 0 , 1000);
< /code>
Dies ist mein Code für die lineare und quadratische Interpolation < /p>
public static (float, float) Linear((float, float) start, (float, float) end, float t)
{
// Clamp t between 0 and 1
t = t > 1 ? 1 : t < 0 ? 0 : t;

// Calculate the new coordinates (Offset + (Distance * t))
float x = MathF.Round(start.Item1 + (end.Item1 - start.Item1) * t, 2);
float y = MathF.Round(start.Item2 + (end.Item2 - start.Item2) * t, 2);

return (x, y);
}

public static (float, float) Quadratic((float, float) start, (float, float) controlPoint, (float, float) end, float t)
{
// Interpolate Start and ControlPoint
var firstInterpolated = Linear(start, controlPoint, t);

// Interpolate ControlPoint and End
var secondInterpolated = Linear(controlPoint, end, t);

// Interpolate the two interpolated points
var result = Linear(firstInterpolated, secondInterpolated, t);

return result;
}

public static float[] Quadratic((float, float) start, (float, float) controlPoint, (float, float) end, int intensity, float t)
{
float[] interpolatedPoints = new float[intensity * 2];
float stride = t;

for (int i = 0; i < intensity * 2; i += 2)
{
var point = Quadratic(start, controlPoint, end, stride);
interpolatedPoints[i] = point.Item1;
interpolatedPoints[i + 1] = point.Item2;
stride += t;
}

return interpolatedPoints;
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post