Foxtable(狐表)用户栏目专家坐堂 → 这段代码在狐表要怎么执行,需要引入什么?


  共有1611人关注过本帖树形打印复制链接

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

帅哥哟,离线,有人找我吗?
zhenghangbo
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:4606 威望:0 精华:0 注册:2018/2/7 14:30:00
这段代码在狐表要怎么执行,需要引入什么?  发帖心情 Post By: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楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110867 积分:564285 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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

 回到顶部
帅哥哟,离线,有人找我吗?
zhenghangbo
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:4606 威望:0 精华:0 注册:2018/2/7 14:30:00
  发帖心情 Post By:2024/7/25 14:27:00 [只看该作者]

For i As Integer = 0, j = polygon.Count - 1 To polygon.Count - 1
这句代码语法错误

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110867 积分:564285 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2024/7/25 14:32:00 [只看该作者]

dim j = polygon.Count - 1
For i As Integer = 0 To polygon.Count - 1

 回到顶部