<i id='5rAId'><tr id='5rAId'><dt id='5rAId'><q id='5rAId'><span id='5rAId'><b id='5rAId'><form id='5rAId'><ins id='5rAId'></ins><ul id='5rAId'></ul><sub id='5rAId'></sub></form><legend id='5rAId'></legend><bdo id='5rAId'><pre id='5rAId'><center id='5rAId'></center></pre></bdo></b><th id='5rAId'></th></span></q></dt></tr></i><div id='5rAId'><tfoot id='5rAId'></tfoot><dl id='5rAId'><fieldset id='5rAId'></fieldset></dl></div>
  • <legend id='5rAId'><style id='5rAId'><dir id='5rAId'><q id='5rAId'></q></dir></style></legend>

      1. <tfoot id='5rAId'></tfoot>
      2. <small id='5rAId'></small><noframes id='5rAId'>

          <bdo id='5rAId'></bdo><ul id='5rAId'></ul>

        在 Cocos2d 中获取贝塞尔曲线问题的导数

        Getting the derivative of a Bezier curve problem in Cocos2d(在 Cocos2d 中获取贝塞尔曲线问题的导数)

        <small id='CUbnn'></small><noframes id='CUbnn'>

          <bdo id='CUbnn'></bdo><ul id='CUbnn'></ul>
            <tbody id='CUbnn'></tbody>
        • <legend id='CUbnn'><style id='CUbnn'><dir id='CUbnn'><q id='CUbnn'></q></dir></style></legend>
        • <i id='CUbnn'><tr id='CUbnn'><dt id='CUbnn'><q id='CUbnn'><span id='CUbnn'><b id='CUbnn'><form id='CUbnn'><ins id='CUbnn'></ins><ul id='CUbnn'></ul><sub id='CUbnn'></sub></form><legend id='CUbnn'></legend><bdo id='CUbnn'><pre id='CUbnn'><center id='CUbnn'></center></pre></bdo></b><th id='CUbnn'></th></span></q></dt></tr></i><div id='CUbnn'><tfoot id='CUbnn'></tfoot><dl id='CUbnn'><fieldset id='CUbnn'></fieldset></dl></div>

              1. <tfoot id='CUbnn'></tfoot>
                • 本文介绍了在 Cocos2d 中获取贝塞尔曲线问题的导数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  In cocos2d you can move a sprite in a Bezier path using ccBezierConfig. That's not my problem though, I have a missile and am trying to make it rotate perpendicular to that point on the curve. I couldn't figure it out for a while and then my friend told me about derivatives. Now I need to find the derivative of a bezier curve apparently. I searched on Google and found it on this page: http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/bezier-der.html. So then I tried implementing rotating the missile with 3 methods here they are:

                  -(float)f:(int)x {
                      if (x == 0)
                          return 1.0f;
                      float result = 1;
                      while (x>0) {
                          result = result*x;
                          x--;
                      }
                      return result;
                  }
                  
                  -(float)B:(float)u i:(int)i n:(int)n {
                      return ([self f:n])/([self f:i]*[self f:(n-i)])*pow(u, (float)i)*pow(1-u, (float)n-i);
                  }
                  
                  -(void)rotateMissile:(float)delta {
                      //Get bezier derivative...
                      float y = [self B:missileP1.controlPoint_1.x i:0 n:2]+[self B:missileP1.controlPoint_2.x i:1 n:2]
                                  *2*(missileP1.controlPoint_1.x - missileP1.controlPoint_2.x);
                  
                      //Take the y and rotate it...
                      missile1.rotation = atanf(y);
                  
                  }
                  

                  The first method is for factorials, the second is supposed to find B in the equation derivative. The 3rd method is supposed to find the actual derivative and rotate the missile by converting slope to degrees using atanf.

                  The rotateMissile is being called continuously like such:

                      [self schedule:@selector(rotateMissile:)];
                  

                  missileP1 is the ccBezierConfig object. missile1 is the missile I am trying to rotate. I'm just really confused about this whole derivative thing (in other words, I'm really lost and confused). I need help trying to figure out whats wrong... Sorry that the code is messy, the equations were long and I could figure out a way to make it less messy.

                  解决方案

                  Actually I don't understand how are you taking a derivative and putting it into a float. That's because Bizier curve is two dimensional parametric curve (it has x and y components). It is not a function y(x). In cubic case it is:

                  x(t) = x0 + x1*t + x2*t*t + x3*t*t*t
                  y(t) = y0 + y1*t + y2*t*t + y3*t*t*t
                  

                  Let's call it form1. So actually it's nothing more then two polynomials of third order. The traditional form of cubic Bezier curve is

                  Note, that B(t) here is a two dimensional vector (x(t), y(t)). So if you have a tradional way defined Bezier curve you can convert it to form1 by evaluating coefficients x0, x1 and son on.

                  If you now have your Bezier curve defined in form1 it is very easy to take the derivative:

                  x'(t) = x1 + 2*x2*t + 3*x3*t*t
                  y'(t) = y1 + 2*y2*t + 3*y3*t*t
                  

                  Now the vector (x'(t), y'(t)) - is the velocity on your bezier curve. It also a tangent vector to your curve. The perpendicular vector will be (-y'(t), x'(t)) or ((y'(t), -(x'(t)).

                  Here are the coefficients:

                  For y coefficients the formula is totally identical. It just will py0, py1, py2, py3 instead of px0, ... .

                  这篇关于在 Cocos2d 中获取贝塞尔曲线问题的导数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                  Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                  Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                  Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                  Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
                  [ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)
                • <i id='0Cbxx'><tr id='0Cbxx'><dt id='0Cbxx'><q id='0Cbxx'><span id='0Cbxx'><b id='0Cbxx'><form id='0Cbxx'><ins id='0Cbxx'></ins><ul id='0Cbxx'></ul><sub id='0Cbxx'></sub></form><legend id='0Cbxx'></legend><bdo id='0Cbxx'><pre id='0Cbxx'><center id='0Cbxx'></center></pre></bdo></b><th id='0Cbxx'></th></span></q></dt></tr></i><div id='0Cbxx'><tfoot id='0Cbxx'></tfoot><dl id='0Cbxx'><fieldset id='0Cbxx'></fieldset></dl></div>

                    • <bdo id='0Cbxx'></bdo><ul id='0Cbxx'></ul>
                          <tbody id='0Cbxx'></tbody>

                        <legend id='0Cbxx'><style id='0Cbxx'><dir id='0Cbxx'><q id='0Cbxx'></q></dir></style></legend>

                      1. <tfoot id='0Cbxx'></tfoot>

                          <small id='0Cbxx'></small><noframes id='0Cbxx'>