你能使用 Html 5 canvas 来计算你沿着河流行驶的距离吗?
我的想法是,你可以画一条穿过河流的线,然后如果你知道河流的总距离,你可以将线的像素长度除以距离。
因此,如果您的线是 760 像素,而河流的距离是 20 英里,那么 760 / 20 = 38 像素 = 1 英里。
当然,如果我的线只是一条直线或一系列线,这将相当简单。然而,我希望我的线能够反映河流的轮廓,因此在某些地方会弯曲。
首先,这是绘制沿河行驶距离的好方法吗?如果不是,什么会更好(我有一种感觉我的数学是错误的!)。
如果这是一个好方法,我将如何考虑线条的弯曲性质以及这可能如何影响线条的像素长度?
My thought was that you could draw a line that traversed the river and then if you knew the total distance of the river you divide the line's pixel length by the distance.
So if your line was 760px and the distance of the river was 20 miles then 760 / 20 = 38px = 1 mile.
Of course if my line was just a straight line or a series of lines this would be fairly simple. However, I would like my line to reflect the contours of the river and as such would be curved in places.
Firstly, is this a good method for plotting distance travelled along a river? If not what would work better (i have a feeling my maths is wrong!).
If this is a good method how would i take into account the curved nature of the line and how this might affect the pixel length of the line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
计算河流长度类似于计算弧长
。
即使您在画布(或任何光栅图像)中完全按照您想要的方式绘制河流,然后计算蓝色像素的数量,您也只能得到与画布宽度/河流距离一样接近的近似答案。
Calculating the length of a river is similar to calculating the Length of an Arc
.
Even if you draw the river exactly as you want it in an canvas(or in any Raster Image for that matter), and then count the amount of blue pixels, you would only be able to get an approximate answer as close as canvaswidth / riverdistance.
我不会使用英里(因为它太粗糙)。使用更短的东西代替(我会使用米,但是 ymmv)。
然后沿着河流的曲率画一条线并计算该线的像素,每个像素代表给定的距离。 (例如,一个像素可以代表 150 米)
I wouldn't use miles (because its too crude). Use something shorter instead (I'd use meters, but ymmv).
Then just draw a line along the curvature of the river and count the pixels of that line, every pixel represents a given distance. (e.G. one pixel could represent 150 meters)