从多边形的侧面绘制等距点

编程入门 行业动态 更新时间:2024-10-27 18:27:45
本文介绍了从多边形的侧面绘制等距点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在绘制具有以下顶点的多边形

I am drawing a polygon with the following vertices

x y -0.02208709 -0.039161304 0.01184081 -0.020268029 0.04578401 -0.001351904 0.02210236 0.039176396 -0.01185226 0.020252146 -0.04578784 0.001352696

使用以下代码

plot(x,y) polygon(x,y) points(mean(x),mean(y),col="red")

现在,我想沿着多边形的侧面绘制50个等距的点.有什么建议怎么做吗?

Now I want to plot 50 equally-spaced points along the sides of polygon. Any suggestion how to do it?

推荐答案

您可以使用sp包中的spsample来完成此操作.

You can do this with spsample from the sp package.

首先,我们将加载库并读取您的顶点.

First we'll load the library and read in your vertices.

library(sp) xy <- read.table(text='x y -0.02208709 -0.039161304 0.01184081 -0.020268029 0.04578401 -0.001351904 0.02210236 0.039176396 -0.01185226 0.020252146 -0.04578784 0.001352696', header=TRUE)

现在从顶点创建一个SpatialLines对象.这有点混乱-如果遇到问题,请参见?SpatialLines和?`SpatialLines-Class`.

Now create a SpatialLines object from the vertices. This is a bit messy - see ?SpatialLines and ?`SpatialLines-Class` if you get stuck.

l <- SpatialLines(list(Lines(Line(rbind(xy, xy[1, ])), ID=1)))

然后采样点并使用as.data.frame(pts)或coordinates(pts)强制转换为data.frame.

Then sample the points and coerce to a data.frame with as.data.frame(pts) or coordinates(pts).

pts <- spsample(l, 50, type="regular") coordinates(pts) # only the head shown here ## x y ## [1,] -0.019343310 -0.03763339 ## [2,] -0.014987452 -0.03520776 ## [3,] -0.010631594 -0.03278213 ## [4,] -0.006275735 -0.03035651 ## [5,] -0.001919877 -0.02793088 ## [6,] 0.002435981 -0.02550525 plot(l) points(pts, pch=20)

更多推荐

从多边形的侧面绘制等距点

本文发布于:2023-08-02 00:02:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1272888.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多边形   侧面

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!