{"id":1370,"date":"2020-03-13T17:15:54","date_gmt":"2020-03-13T09:15:54","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=1370"},"modified":"2020-09-28T21:54:11","modified_gmt":"2020-09-28T13:54:11","slug":"%e7%82%b9%e6%8a%95%e5%bd%b1%e7%9a%84%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=1370","title":{"rendered":"\u70b9\u6295\u5f71\u7684\u793a\u4f8b"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>using UnityEngine;\n\npublic class CalcPointProj : MonoBehaviour\n{\n    public Transform Line0;\n    public Transform Line1;\n    public Transform CalcPoint;\n\n    \/\/ \u8ba1\u7b97pc\u70b9\u5728p1\u548cp0\u70b9\u8fde\u6210\u7ebf\u7684\u6295\u5f71\n    public static Vector3 PointProj(Vector3 p0, Vector3 p1, Vector3 pc)\n    {\n        var n0 = p1 - p0;\n        var v0 = pc - p0;\n        var d = Vector3.Distance(p1, p0);\n        var k = Vector3.Dot(n0, v0) \/ ( d * d );\n        return p0 + n0 * k;\n    }\n\n    void OnDrawGizmos()\n    {\n        if (Line0 != null &amp;&amp; Line1 != null &amp;&amp; CalcPoint != null)\n        {\n            Gizmos.DrawLine( Line0.position, Line1.position );\n            Gizmos.DrawSphere( PointProj(Line0.position, Line1.position, CalcPoint.position) , 1);\n        }\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1370"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1370"}],"version-history":[{"count":1,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1370\/revisions"}],"predecessor-version":[{"id":1371,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/1370\/revisions\/1371"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}