久久久久久久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 中查找多邊形的中心點(diǎn)

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

      <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 中查找多邊形的中心點(diǎn)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                我有一個(gè)來(lái)自谷歌地圖的地點(diǎn)"對(duì)象,它有一組坐標(biāo),代表給定位置的邊界框,比如倫敦.每組坐標(biāo)都有一個(gè)緯度和經(jīng)度.

                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.

                我已經(jīng)編寫(xiě)了以下代碼來(lái)查找中心點(diǎn),但我不確定它是否確實(shí)產(chǎn)生了中心點(diǎn).如果多邊形有 5 個(gè)點(diǎn)而不是 4 個(gè)呢?另外,這是否可以以更有效的方式完成,操作更少?

                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)])
                

                示例.

                推薦答案

                這應(yīng)該得到 centroid 任何 區(qū)域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());
                }());
                

                關(guān)于 jsfiddle

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

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

                相關(guān)文檔推薦

                Use IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
                anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 項(xiàng)目中不起作用)
                Ionic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用異步數(shù)據(jù)更新 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 中,如何創(chuàng)建使用 Ionic 組件的自定義指令?)
                Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(將 ViewChild 用于動(dòng)態(tài)元素 - 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. 主站蜘蛛池模板: 一道本不卡 | 亚洲精品无人区 | 国产精品成av人在线视午夜片 | 国产午夜亚洲精品不卡 | 亚洲一区电影 | 一区二区中文 | 国产91丝袜| 成人av一区 | 成人久久久 | 午夜av电影| 色视频网站免费 | 日日夜夜精品视频 | 久久视频免费观看 | 天天操操操操操 | 亚洲精品视频在线 | 99视频入口 | 亚洲av毛片 | 亚洲精品一区二三区不卡 | 黑人久久久| 精品久久99| 成人国产精品免费观看 | 91在线观看| 中文在线播放 | www.99精品| 国产精品久久久久久久久久久久冷 | 国产极品粉嫩美女呻吟在线看人 | 国产视频不卡一区 | 一级毛片色一级 | 天天干夜夜操 | 国产在线观看 | 国产精品亚洲综合 | 日韩欧美手机在线 | 亚洲v区 | 欧美视频成人 | 免费同性女女aaa免费网站 | 亚洲精品18 | 羞羞视频在线观免费观看 | 久草网址 | 国产在线1 | 久久久久九九九女人毛片 | 91精品国产91久久久久久 |