Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共4 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:这段代码在狐表要怎么执行,需要引入什么?

1楼
zhenghangbo 发表于:2024/7/25 13:49:00
Imports System.Numerics

Module Module1

Sub Main()
' 定义多边形的顶点
Dim polygonPoints As New List(Of PointLatLng) From {
New PointLatLng(40.7128, -74.0060),
New PointLatLng(40.7128, -74.0050),
New PointLatLng(40.7118, -74.0050),
New PointLatLng(40.7118, -74.0060),
New PointLatLng(40.7128, -74.0060)
}

' 待检测的点
Dim testPoint As New PointLatLng(40.7125, -74.0055)

' 检查点是否在多边形内
Dim isInside As Boolean = IsPointInPolygon(testPoint, polygonPoints)

Console.WriteLine($"The point ({testPoint.Latitude}, {testPoint.Longitude}) is inside the polygon? {isInside}")
Console.ReadLine()
End Sub

Public Class PointLatLng
Public Property Latitude As Double
Public Property Longitude As Double

Public Sub New(latitude As Double, longitude As Double)
Me.Latitude = latitude
Me.Longitude = longitude
End Sub
End Class

Public Function IsPointInPolygon(ByVal point As PointLatLng, ByVal polygon As List(Of PointLatLng)) As Boolean
Dim x As Double = point.Longitude
Dim y As Double = point.Latitude
Dim inside As Boolean = False

For i As Integer = 0, j = polygon.Count - 1 To polygon.Count - 1
Dim xi As Double = polygon(i).Longitude
Dim yi As Double = polygon(i).Latitude
Dim xj As Double = polygon(j).Longitude
Dim yj As Double = polygon(j).Latitude

If ((yi > y) <> (yj > y)) AndAlso (x < (xj - xi) * (y - yi) / (yj - yi) + xi) Then
inside = Not inside
End If

j = i
Next

Return inside
End Function

End Module
2楼
有点蓝 发表于:2024/7/25 14:05:00
添加这个dll的引用:System.Numerics.dll

全局代码
Public Class PointLatLng
Public Property Latitude As Double
Public Property Longitude As Double

Public Sub New(latitude As Double, longitude As Double)
Me.Latitude = latitude
Me.Longitude = longitude
End Sub
End Class

Public Function IsPointInPolygon(ByVal point As PointLatLng, ByVal polygon As List(Of PointLatLng)) As Boolean
Dim x As Double = point.Longitude
Dim y As Double = point.Latitude
Dim inside As Boolean = False

For i As Integer = 0, j = polygon.Count - 1 To polygon.Count - 1
Dim xi As Double = polygon(i).Longitude
Dim yi As Double = polygon(i).Latitude
Dim xj As Double = polygon(j).Longitude
Dim yj As Double = polygon(j).Latitude

If ((yi > y) <> (yj > y)) AndAlso (x < (xj - xi) * (y - yi) / (yj - yi) + xi) Then
inside = Not inside
End If

j = i
Next

Return inside
End Function

窗口按钮
Dim polygonPoints As New List(Of PointLatLng) From {
New PointLatLng(40.7128, -74.0060),
New PointLatLng(40.7128, -74.0050),
New PointLatLng(40.7118, -74.0050),
New PointLatLng(40.7118, -74.0060),
New PointLatLng(40.7128, -74.0060)
}

' 待检测的点
Dim testPoint As New PointLatLng(40.7125, -74.0055)

' 检查点是否在多边形内
Dim isInside As Boolean = IsPointInPolygon(testPoint, polygonPoints)
if isInside 
output.show("待检测的点在多边形内")
endif
3楼
zhenghangbo 发表于:2024/7/25 14:27:00
For i As Integer = 0, j = polygon.Count - 1 To polygon.Count - 1
这句代码语法错误
4楼
有点蓝 发表于:2024/7/25 14:32:00
dim j = polygon.Count - 1
For i As Integer = 0 To polygon.Count - 1
共4 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03906 s, 2 queries.