{"id":535,"date":"2017-12-12T20:44:53","date_gmt":"2017-12-12T12:44:53","guid":{"rendered":"http:\/\/www.whudj.cn\/?p=535"},"modified":"2017-12-19T15:33:32","modified_gmt":"2017-12-19T07:33:32","slug":"b-spline%e5%85%ad%e7%bb%99%e5%ae%9a%e5%8f%82%e6%95%b0%e6%b1%82%e7%82%b9de-boor-%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.whudj.cn\/?p=535","title":{"rendered":"B-Spline(\u516d):\u7ed9\u5b9a\u53c2\u6570\u6c42\u70b9(de Boor \u7b97\u6cd5)"},"content":{"rendered":"<p>\u7ed9\u5b9a\u53c2\u6570u,\u8ba1\u7b97\u53c2\u6570\u66f2\u7ebf\u4e0a\u5bf9\u5e94\u70b9\u7684\u8fd0\u7b97\u79f0\u4e3a\u6c42\u503c(Evalute)\u64cd\u4f5c\u3002\u53cd\u4e4b\uff0c\u79f0\u4e4b\u4e3a\u6c42\u89e3(Solve)\u3002\u8fd9\u4e00\u8282\u7684\u76ee\u6807\u662f\u4ecb\u7ecd\u5fb7\u5e03\u5c14(de Boor)\u57281972\u5e74\u63d0\u51fa\u7684\u6570\u503c\u7a33\u5b9a\u7684\u6c42\u503c\u65b9\u6cd5\u3002\u5b83\u662f\u5fb7\u5229\u65af\u7279\u91cc\u5965(De Casteljau\u2019s)\u7b97\u6cd5\u7684\u4e00\u822c\u5316\u5f62\u5f0f\u3002<!--more--><\/p>\n<p>\u8fd9\u4e00\u8282\u6211\u7684\u5b89\u6392\u4e0eDr.Shene\u7565\u6709\u4e0d\u540c\uff0c\u9996\u5148\u662f\u5728\u7ae0\u8282\u987a\u5e8f\u4e0a\uff0cDr.Shene\u5728B-Spline\u6027\u8d28\u8bf4\u660e\u540e\u5148\u8bb2\u89e3\u4e86B-Spline\u7684\u6c42\u5bfc\uff0c\u7136\u540e\u662f\u5728\u8282\u70b9\u63d2\u5165\u7b97\u6cd5\u7ae0\u8282\u4e2d\u4ecb\u7ecd\u4e86De Boor\u7b97\u6cd5\u3002\u6211\u6253\u7b97\u5148\u884c\u4ecb\u7ecd\u3002\u53e6\u5916\uff0cDr.Shene \u662f\u4ece\u8282\u70b9\u63d2\u5165\u7684\u89d2\u5ea6\u6765\u8bb2\u89e3\u7684De Boor\u7b97\u6cd5\uff0c\u6211\u56e0\u4e3a\u5e0c\u671b\u201c\u5f3a\u8c03\u201dDe Boor\u4e0eDe Casteljau \u7b97\u6cd5\u7684\u5bf9\u5e94\u5173\u7cfb\uff0c\u8ba1\u5212\u53c2\u8003<a href=\"https:\/\/en.wikipedia.org\/wiki\/De_Boor%27s_algorithm\">wikipedia\u5bf9de Boor\u7b97\u6cd5\u7684\u8bb2\u89e3<\/a>\u6765\u4ecb\u7ecdDe Boor\u7b97\u6cd5\u3002\u5b9e\u8d28\u4e0a\uff0cDr.shene\u5bf9De Boor\u7b97\u6cd5\u7684\u7406\u89e3\u5f53\u7136\u66f4\u52a0\u6df1\u5165\uff0c\u800c\u6211\u6253\u7b97\u7ed9\u51fa\u5b83\u7684\u201cNaive\u201d\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u53c2\u6570\\(u \\in[u_p,u_{m-p}]\\),\u6c42\u89e3\u66f2\u7ebf\u4e0a\u4e00\u70b9\u7684\u6b65\u9aa4\u5982\u4e0b:<\/p>\n<p>1\uff09\u9996\u5148\u786e\u5b9a u \u6240\u5728\u7684\u533a\u95f4\\([u_k,u_{k+1})\\)\u3002\u56e0\u4e3a\u8282\u70b9\u533a\u95f4\u4e3a\u6709\u5e8f\u975e\u9012\u51cf\u6570\u7ec4\uff0c\u56e0\u6b64\u53ef\u4ee5\u4f7f\u7528<span class=\"lang:c++ decode:true crayon-inline \">std::upper_bound()-1<\/span>\u00a0 \u6765\u786e\u5b9ak\u3002<\/p>\n<p>2\uff09\u786e\u5b9a\u5728\u533a\u95f4\\([u_k,u_{k+1})\\)\u7684p+1\u4e2a\u6784\u6210\u66f2\u7ebf\u51f8\u5305\uff08\u5373\u5bf9\u5e94\u57fa\u51fd\u6570\u4e0d\u4e3a0\uff09\u7684\u63a7\u5236\u70b9\\(P_{k-p},&#8230;,P_k\\)\u3002<\/p>\n<p>3\uff09\u5bf9\u63a7\u5236\u70b9\u51f8\u5305\u8fdb\u884cp\u6b21\u201c\u5207\u89d2\u201d\u3002\u8fed\u4ee3\u5f0f\u4e3a $$\\begin{align*} &amp; P_{i,r}=(1-\\alpha _{i,r})P_{i-1,r-1}+\\alpha _{i,r}P_{i,r-1} \\\\ &amp; \\alpha _{i,r} = \\frac{u-u_i}{u_{i+p+1-r}-u_i}\u00a0 \\\\ \\end{align*}$$\u9700\u8981\u6ce8\u610f\u7684\u662f\u5bf9\\(\\alpha _{i,r}\\)\u7684\u5904\u7406\uff0c\u56e0\u4e3a\u6709\u53ef\u80fd\u5b58\u5728\u91cd\u590d\u8282\u70b9\uff0c\u6240\u4ee5\u89c4\u5b9a\\(\\frac{0}{0}=0\\)\u3002<\/p>\n<p>\u6211\u7684C++\u7248\u672c\u7684\u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:c++ decode:true\">Point BSpline::Evaluate(double u)\r\n{\r\n\tconst std::vector&lt;double&gt;&amp; knots = m_vecKnots;\r\n\tint p = m_nDegree;\r\n\r\n\t\/\/\u67e5\u627e u \u6240\u5728\u533a\u95f4\r\n\tint k = std::distance(knots.begin(),std::upper_bound(knots.begin(), knots.end(), u))-1;\r\n\t\r\n\t\/\/\u7533\u8bf7 p+1\u4e2apoint,\u5206\u522b\u5b58\u653e P_{k-p},...,P_k\r\n\tPoint *pArray = new Point[p+1];\r\n\tstd::copy(m_vecCVs.begin() + k - p, m_vecCVs.begin() + k + 1, pArray);\r\n\r\n\t\/\/\u8fed\u4ee3 p\u6b21\r\n\tfor (int r = 1;r &lt;= p;++r)\r\n\t{\r\n\t\t\/\/i \u4ece k \u5230 k-p+1\r\n\t\tfor (int i = k,j=p;i &gt;= k - p+r;--i,--j)\r\n\t\t{\r\n\t\t\tdouble alpha = u - knots[i];\r\n\t\t\tdouble dev = (knots[i+p+1-r]-knots[i]);\r\n\t\t\talpha = (dev !=0)? alpha \/ dev : 0;\r\n\r\n\t\t\tpArray[j] = (1.0 - alpha)*pArray[j - 1] + alpha * pArray[j];\r\n\t\t}\r\n\t}\r\n\r\n\t\/\/\u6240\u6c42\u70b9\u662f\u6700\u540e\u4e00\u4e2a\r\n\tPoint pt  = pArray[p];\r\n\tdelete[]pArray;\r\n\treturn pt;\r\n}<\/pre>\n<p>\u4e0e\u5fb7\u5361\u65af\u7279\u5229\u5965\u7b97\u6cd5\u7684\u5bf9\u6bd4\uff1a<\/p>\n<p>1\uff09\u5fb7\u5361\u65af\u7279\u5229\u5965\u7b97\u6cd5\u5bf9\u63a7\u5236\u591a\u8fb9\u5f62\u7684\u201c\u5207\u89d2\u201d\u7684\u6bd4\u4f8b\u59cb\u7ec8\u662f 1-u : u \u4e0d\u53d8\uff0c\u800c\u5fb7\u5e03\u5c14\u7b97\u6cd5\u7684\u6bd4\u4f8b\u4e0e\u53c2\u6570\u533a\u95f4\u76f8\u5173\u3002<\/p>\n<p>2\uff09\u5fb7\u5361\u65af\u7279\u5229\u5965\u4f5c\u7528\u5728\u5168\u90e8 p+1\u4e2a\u63a7\u5236\u70b9\u4e0a\uff0cde Boor\u7b97\u6cd5\u4e5f\u662f\u4f5c\u7528\u5728p+1\u4e2a\u63a7\u5236\u70b9\u4e0a\uff0c\u4f46\u662f\u4e0d\u662fB\u6837\u6761\u7684\u5168\u90e8\u63a7\u5236\u70b9\u3002\u8fd9\u5c31\u662f\u6211\u4eec\u8bf4\u7684Bezier\u66f2\u7ebf\u662f\u5168\u5c40\u7684\uff0c\u800cB\u6837\u6761\u5177\u6709\u201c\u5c40\u90e8\u201d\u6027\u3002<\/p>\n<p>3\uff09\u8fd9\u4e2a\u662f\u7eaf\u4ece\u7f16\u7a0b\u89d2\u5ea6\u63d0\u9192\u5927\u5bb6\u6ce8\u610f\u7684\uff0c\u5c31\u662fde\u00a0Casteljau\u2019s \u65b9\u6cd5\u7ed9\u7684\u9012\u63a8\u5f0f\u662f\u00a0\\(P_{i,r} = (1-\\alpha)P_{i,r-1}+\\alpha P_{i+1,r-1}\\)\u65b9\u5f0f\u7684\uff0c\u6240\u4ee5\u9012\u63a8\u65f6i\u662f\u9012\u589e\u7684\uff0c\u800cde-Boor\u7684\u9012\u63a8\u5f0f\u662f\\(P_{i,r} = (1-\\alpha)P_{i-1,r-1}+\\alpha P_{i,r-1}\\)\u65b9\u5f0f\u7684\uff0c\u9012\u63a8\u65f6i\u8981\u9012\u51cf\uff0c\u5426\u5219\u5c31\u4f1a\u5199\u9519\u3002<\/p>\n<hr \/>\n<p>\u5fb7\u5e03\u5c14\u56e0\u4e3a\u5728\u5bf9\u6570\u5b66\u7814\u7a76\u5f97\u5353\u8457\u8d21\u732e\uff0c\u83b7\u5f972003\u5e74\u7f8e\u56fd\u56fd\u5bb6\u79d1\u5b66\u5956\u7ae0\uff08<a href=\"https:\/\/en.wikipedia.org\/wiki\/National_Medal_of_Science\">National Medal of Science<\/a>\uff09<\/p>\n<div id=\"attachment_542\" style=\"width: 360px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-542\" class=\"size-full wp-image-542\" src=\"http:\/\/www.whudj.cn\/wp-content\/uploads\/2017\/12\/deboor_bush.jpg\" alt=\"\" width=\"350\" height=\"220\" \/><p id=\"caption-attachment-542\" class=\"wp-caption-text\">3\/14\/05-Washington, DC&#8211;President George W. Bush honors Laureates of the National Medal of Technology and Science in the East Room of the White House.<br \/>Photo by Ryan K Morris<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u53c2\u6570u,\u8ba1\u7b97\u53c2\u6570\u66f2\u7ebf\u4e0a\u5bf9\u5e94\u70b9\u7684\u8fd0\u7b97\u79f0\u4e3a\u6c42\u503c(Evalute)\u64cd\u4f5c\u3002\u53cd\u4e4b\uff0c\u79f0\u4e4b &hellip; <a href=\"http:\/\/www.whudj.cn\/?p=535\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"_links":{"self":[{"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/posts\/535"}],"collection":[{"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=535"}],"version-history":[{"count":11,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/posts\/535\/revisions"}],"predecessor-version":[{"id":609,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=\/wp\/v2\/posts\/535\/revisions\/609"}],"wp:attachment":[{"href":"http:\/\/www.whudj.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=535"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.whudj.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}