Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

Discussions

Tokter Tokter
  • Can someone check my math?

    @AdamSpeight2008:

     

    (b^2 * t * P1):

    b^2 = (3*(1-t))^2 = 9(1-t)^2 instead of 3(1-t)^2

    so it should be (3 * a^2 * t * P1) imho

  • Can someone check my math?

    , Minh wrote

    Tokter,

    Looking more into it, your routine isn't a direct reflection of this formula:

    Can you point me to how you worked that out?

     

    First you get the extended form of your formula http://www.wolframalpha.com/input/?i=%281-t%29%5E3*P0%2B3*%281-t%29%5E2*t*P1%2B3*%281-t%29*t%5E2*P2%2Bt%5E3*P3:

    -P0*t^3 + 3*P0*t^2 - 3*P0*t + P0 + 3*P1*t^3 - 6*P1*t^2 + 3*P1*t - 3*P2*t^3 + 3*P2*t^2 + P3*t^3

    Then you factorize for t^3, t^2 and t

    t^3(-P0 + 3*P1 - 3*P2 + P3) + t^2(3*P0 - 6*P1 + 3*P2) + t(3*P1 - 3* P0) + P0

    then you substitute:

    c = 3*(P1 - P0)
    b = 3*(P2 - P1) - c
    a = P3 - P0 - c -b

    And you get:

    B(t) = (a * t^3) + (b * t^2) + (c * t) + P0

  • Can someone check my math?

            public PointF CubicBezier(float t, PointF p0, PointF p1, PointF p2, PointF p3)
            {
                float cx = 3 * (p1.X - p0.X);
                float bx = 3 * (p2.X - p1.X) - cx;
                float ax = p3.X - p0.X - cx - bx;
                float cy = 3 * (p1.Y - p0.Y);
                float by = 3 * (p2.Y - p1.Y) - cy;
                float ay = p3.Y - p0.Y - cy - by;
                float tCubed = t * t * t;
                float tSquared = t * t;
                float resultX = (ax * tCubed) + (bx * tSquared) + (cx * t) + p0.X;
                float resultY = (ay * tCubed) + (by * tSquared) + (cy * t) + p0.Y;
                return new PointF(resultX, resultY);
            }

  • .Net color ramp function?

    That's how I would do it:

     

            private Color ColorLerp(Color a, Color b, float l)
            {
                return Color.FromArgb(
                    (int)((float)a.A + ((float)b.A - (float)a.A) * l),
                    (int)((float)a.R + ((float)b.R - (float)a.R) * l),
                    (int)((float)a.G + ((float)b.G - (float)a.G) * l),
                    (int)((float)a.B + ((float)b.B - (float)a.B) * l)
                    );
            }
     

  • A New Riddle

    There is nothing new about that riddle Tongue Out

    The hotel has $25 + the mailman has $2 = $27 that the friends payed.

  • First WPF/SL and now Windows Gadgets

    The video is well made, but the iA app looks completely useless to me.

  • Managed DirectX for Windows 8 metro apps - Draft

    @spivonious:Nothing has been announced regarding the future of XNA.

  • directX debugging

    That was really cool, I hope we get that for XNA too!

  • Scientists prove Global Warming caused by the sun, not humans.

    Still not a fair comparison. You would have to take a look cradle to cradle. Then the hummer would be more environmentally friendly then a Prius.

    This study, done by a marketing firm, has been debunked so many times. I can't believe people still believe that...

  • SQL Server Throughput

    @W3bbo:For what it's worth. Using Sql2005 on my dev machine (so no network involved).

    Using your method, but within a transaction, it inserts 15,000 records in 3s.

                var start = DateTime.Now;
                using (SqlConnection con = GetConnection())
                {
                    var tran = con.BeginTransaction();
                    SqlCommand cmd = con.CreateCommand();
                    cmd.Transaction = tran;
                    cmd.CommandText = "insert into test (value) values (@value)";
                    cmd.Parameters.Add("@value", SqlDbType.Int);
    
                    foreach (int r in recordsToInsert)
                    {
                        cmd.Parameters["@value"].Value = r;
                        cmd.ExecuteNonQuery();
                    }
                    tran.Commit();
                }
                var end = DateTime.Now;
                tbOutput.Text = string.Format("Elapsed time {0}", (end - start));

     

    Using a stored procedure and batching all 15,000 inserts into one command, about 0.4s

                var start = DateTime.Now;
                using (SqlConnection con = GetConnection())
                {
                    var tran = con.BeginTransaction();
                    SqlCommand cmd = con.CreateCommand();
                    cmd.Transaction = tran;
                    var sb = new StringBuilder();
                    foreach (int r in recordsToInsert)
                    {
                        sb.AppendFormat("exec Insert_Test {0};", r);
                    }
                    cmd.CommandText = sb.ToString();
                    cmd.ExecuteNonQuery();
                    tran.Commit();
                }
                var end = DateTime.Now;
                tbOutput.Text = string.Format("Elapsed time {0}", (end - start));