Subscribe to:
Post Comments (Atom)
We are hackers. We've used a lot of languages. Now we are going to learn another language. It is English. --- What is Hacker's Cafe? Good question. It have held in Tokyo. Let's get together with laptops, hack and hack. Feel free to join us. Please contact us: akio0911 (at) gmail (dot) com. Web site: Hacker's Cafe
5 comments:
i couldn't understand the source code , could you please comment it ? ,
or give some explanation of the mathematical solution,
i'm making graphics application using python and i need this
my curve has the structure : [point,point,point....]
point = [handler,vertex,handler]
handler,vertex = (x,y)
could you help me ?
Almost same:
for c in curves:
P1, P2, P3 = (
(c[0], c[1]),
(c[2], c[3]),
(c[4], c[5]))
here, any c in curves are [handler, handler, point]
P0 and P3 are terminal points of each bezier curves.
sorry
s/point/vertex/g
This works fine for me when you have only one curve.
private List FindPointsForBounds(Point P0, Point P1, Point P2, Point P3)
{
List toReturn = new List();
int A = P3.X - 3 * P2.X + 3 * P1.X - P0.X;
int B = 3 * P2.X - 6 * P1.X + 3 * P0.X;
int C = 3 * P1.X - 3 * P0.X;
int D = P0.X;
int E = P3.Y - 3 * P2.Y + 3 * P1.Y - P0.Y;
int F = 3 * P2.Y - 6 * P1.Y + 3 * P0.Y;
int G = 3 * P1.Y - 3 * P0.Y;
int H = P0.Y;
float x, y;
float xMin = int.MaxValue;
float yMin = int.MaxValue;
float xMax = 0;
float yMax = 0;
for (float t = 0.0f; t <= 1.0f; t += 0.01f)
{
x = A * t * t * t + B * t * t + C * t + D;
if (x < xMin)
xMin = x;
if (x > xMax)
xMax = x;
y = E * t * t * t + F * t * t + G * t + H;
if (y < yMin)
yMin = y;
if (y > yMax)
yMax = y;
}
toReturn.Add(new Point((int)xMin, (int)yMin));
toReturn.Add(new Point((int)xMax, (int)yMax));
return toReturn;
}
Thank you very much for this algorithm, it helped me a lot!
Post a Comment