久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <bdo id='apqub'></bdo><ul id='apqub'></ul>

    1. <i id='apqub'><tr id='apqub'><dt id='apqub'><q id='apqub'><span id='apqub'><b id='apqub'><form id='apqub'><ins id='apqub'></ins><ul id='apqub'></ul><sub id='apqub'></sub></form><legend id='apqub'></legend><bdo id='apqub'><pre id='apqub'><center id='apqub'></center></pre></bdo></b><th id='apqub'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='apqub'><tfoot id='apqub'></tfoot><dl id='apqub'><fieldset id='apqub'></fieldset></dl></div>
    2. <small id='apqub'></small><noframes id='apqub'>

      <legend id='apqub'><style id='apqub'><dir id='apqub'><q id='apqub'></q></dir></style></legend>
    3. <tfoot id='apqub'></tfoot>

      在 JavaScript 中查找多邊形的中心點

      Find centerpoint of polygon in JavaScript(在 JavaScript 中查找多邊形的中心點)

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

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

              • 本文介紹了在 JavaScript 中查找多邊形的中心點的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我有一個來自谷歌地圖的地點"對象,它有一組坐標,代表給定位置的邊界框,比如倫敦.每組坐標都有一個緯度和經度.

                I have a "place" object from Google Maps which has a set of coordinates that represent a bounding box for a given location, say London. Each set of coordinates has a latitude and longitude.

                我已經編寫了以下代碼來查找中心點,但我不確定它是否確實產生了中心點.如果多邊形有 5 個點而不是 4 個呢?另外,這是否可以以更有效的方式完成,操作更少?

                I have written the below code to find the centerpoint, but I am not sure if it does actually produce the centerpoint. What if the polygon has 5 points instead of 4? Also, can this be done in a more efficient way, with less operations?

                function average(array) {
                  // Add together and then divide by the length
                  return _.reduce(array, function (sum, num) {
                    return sum + num;
                  }, 0) / array.length;
                }
                
                // I have a two-dimensional array that I want to get the average of
                
                var coords = [
                  [ -1.2, 5.1 ],
                  [ -1.3, 5.2 ],
                  [ -1.8, 5.9 ],
                  [ -1.9, 5.8 ]
                ]
                
                // So I get the first column
                
                var lats = coords.map(function (coord) {
                  return coord[0];
                })
                
                // Then the second
                
                var longs = coords.map(function (coord) {
                  return coord[1];
                })
                
                // And average each column out
                
                console.log([average(lats), average(longs)])
                

                示例.

                推薦答案

                這應該得到 centroid 任何 區域wiki/多邊形" rel="noreferrer">多邊形

                This should get the centroid of the area of any polygon

                /*jslint sub: true, maxerr: 50, indent: 4, browser: true */
                /*global console */
                
                (function () {
                    "use strict";
                
                    function Point(x, y) {
                        this.x = x;
                        this.y = y;
                    }
                
                    function Region(points) {
                        this.points = points || [];
                        this.length = points.length;
                    }
                
                    Region.prototype.area = function () {
                        var area = 0,
                            i,
                            j,
                            point1,
                            point2;
                
                        for (i = 0, j = this.length - 1; i < this.length; j=i,i++) {
                            point1 = this.points[i];
                            point2 = this.points[j];
                            area += point1.x * point2.y;
                            area -= point1.y * point2.x;
                        }
                        area /= 2;
                
                        return area;
                    };
                
                    Region.prototype.centroid = function () {
                        var x = 0,
                            y = 0,
                            i,
                            j,
                            f,
                            point1,
                            point2;
                
                        for (i = 0, j = this.length - 1; i < this.length; j=i,i++) {
                            point1 = this.points[i];
                            point2 = this.points[j];
                            f = point1.x * point2.y - point2.x * point1.y;
                            x += (point1.x + point2.x) * f;
                            y += (point1.y + point2.y) * f;
                        }
                
                        f = this.area() * 6;
                
                        return new Point(x / f, y / f);
                    };
                
                    var polygon = [
                            {"x": -1.2, "y": 5.1},
                            {"x": -1.3, "y": 5.2},
                            {"x": -1.8, "y": 5.9},
                            {"x": -1.9, "y": 5.8}
                        ],
                        region = new Region(polygon);
                
                    console.log(region.centroid());
                }());
                

                關于 jsfiddle

                這篇關于在 JavaScript 中查找多邊形的中心點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Use IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
                anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 項目中不起作用)
                Ionic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用異步數據更新 Observable)
                Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
                In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何創建使用 Ionic 組件的自定義指令?)
                Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動態元素 - Angular 2 amp;離子2)

                <small id='20RZF'></small><noframes id='20RZF'>

                  <tbody id='20RZF'></tbody>
                    <bdo id='20RZF'></bdo><ul id='20RZF'></ul>
                        <i id='20RZF'><tr id='20RZF'><dt id='20RZF'><q id='20RZF'><span id='20RZF'><b id='20RZF'><form id='20RZF'><ins id='20RZF'></ins><ul id='20RZF'></ul><sub id='20RZF'></sub></form><legend id='20RZF'></legend><bdo id='20RZF'><pre id='20RZF'><center id='20RZF'></center></pre></bdo></b><th id='20RZF'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='20RZF'><tfoot id='20RZF'></tfoot><dl id='20RZF'><fieldset id='20RZF'></fieldset></dl></div>
                        <tfoot id='20RZF'></tfoot>

                      1. <legend id='20RZF'><style id='20RZF'><dir id='20RZF'><q id='20RZF'></q></dir></style></legend>

                        1. 主站蜘蛛池模板: 国产午夜亚洲精品不卡 | 在线精品一区二区 | www精品美女久久久tv | 日韩成人国产 | 自拍偷拍一区二区三区 | 久久精品91 | 久久久蜜臀国产一区二区 | 自拍偷拍第一页 | 国产精品免费视频一区 | 亚洲国产精品一区二区第一页 | 福利视频网站 | 亚洲一区成人 | 91免费观看 | 久久精品青青大伊人av | 日韩在线视频精品 | 亚洲精品久久久久久久久久久 | 爱爱免费视频 | 久草.com| 久久69精品久久久久久国产越南 | 一区二区手机在线 | 精品国产高清一区二区三区 | 99久久久无码国产精品 | 成人欧美一区二区三区黑人孕妇 | 精品久久久久久久久久久院品网 | 日韩一区二区在线视频 | 久久一视频 | 天天操人人干 | 日韩久久久久久 | 国产日韩欧美精品一区二区三区 | 九色国产| 成人欧美一区二区三区1314 | 国产精品久久久久久久久久久久冷 | 色成人免费网站 | 一区二区小视频 | 国产精品成人久久久久 | 青青草视频网 | 国产成人综合在线 | 狠狠草视频 | 亚洲精品久久久久久久久久吃药 | 国产精品国产三级国产aⅴ入口 | 久久99精品视频 |