ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¸¨ÂI°ÝÃD....(§Ú¥Ø«e±q¥¼¨ì¹Lªº»â°ì)

¦^´_ 1# ui123
B°Ï¸É§¹(6,6),(5,5)§Î¦¨¥W¦hÃä§Î
§PÂ_ªººtºâªk¥i¥H°Ñ¦Ò http://www.csie.ntnu.edu.tw/~u91029/Polygon.html
¸Ì­± §PÂ_¤@­ÓÂI¬O§_¦b²³æ¦hÃä§Î¤º³¡¸Ì­± ³o¤@¬q

TOP

¥»©«³Ì«á¥Ñ stillfish00 ©ó 2013-11-13 00:27 ½s¿è

¦^´_ 4# ui123
¥L¬OC/C++¼gªº¡A§ï¦¨VBA¤j¬ù¦p¤U
  1. Function pointInPoly(ptx As Double, pty As Double, arPoly) As Boolean
  2.     Dim i As Long, j As Long
  3.     Dim pix As Double, piy As Double
  4.     Dim pjx As Double, pjy As Double
  5.    
  6.     For i = 1 To UBound(arPoly) - 1
  7.         j = i + 1
  8.         pix = arPoly(i, 1): piy = arPoly(i, 2)
  9.         pjx = arPoly(j, 1): pjy = arPoly(j, 2)
  10.         
  11.         '¤£¥]§tÂI¦b¦hÃä§Î½u¤W
  12.         If Not (piy > pty) = (pjy > pty) Then
  13.             If ptx < (pjx - pix) * (pty - piy) / (pjy - piy) + pix Then pointInPoly = Not pointInPoly
  14.         End If
  15.     Next
  16. End Function
½Æ»s¥N½X
§Q¥Î¥L¼g¤@­Ó¦Û­q¨ç¼ÆRegionABC
  1. Function RegionABC(x As Double, y As Double, RegionA As Range, RegionB As Range, RegionC As Range) As String
  2.     '¤£¥]§tÂI¦bABCÃä½t
  3.     If pointInPoly(x, y, RegionA.Value) Then RegionABC = "A": Exit Function
  4.     If pointInPoly(x, y, RegionB.Value) Then RegionABC = "B": Exit Function
  5.     If pointInPoly(x, y, RegionC.Value) Then RegionABC = "C": Exit Function
  6.     RegionABC = "¤£¦bABC"
  7. End Function
½Æ»s¥N½X
¥ý¸É»ôB°ÏªºÂI¡A
¨Ï¥Î¡A¨Ò¦p¦bO4¤½¦¡¥´¤W  "=RegionABC(M4,N4,$C$4:$D$8,$C$10:$D$16,$C$18:$D$22)"

TOP

¦^´_ 10# ML089
¦Û­q¨ç¼Æ
  1. Function PolyArea(rngPoly As Range)
  2.     Dim i As Long, j As Long
  3.     Dim pix As Double, piy As Double
  4.     Dim pjx As Double, pjy As Double
  5.     Dim arPoly, area As Double
  6.         
  7.     arPoly = rngPoly.Value
  8.     If UBound(arPoly, 2) <> 2 _
  9.         Or arPoly(1, 1) <> arPoly(UBound(arPoly), 1) _
  10.         Or arPoly(1, 2) <> arPoly(UBound(arPoly), 2) Then PolyArea = CVErr(xlErrRef): Exit Function
  11.    
  12.     area = 0
  13.     For i = 1 To UBound(arPoly) - 1
  14.         j = i + 1
  15.         pix = arPoly(i, 1): piy = arPoly(i, 2)
  16.         pjx = arPoly(j, 1): pjy = arPoly(j, 2)
  17.         
  18.         area = area + pix * pjy
  19.         area = area - piy * pjx
  20.     Next
  21.     PolyArea = Abs(area) / 2
  22. End Function
½Æ»s¥N½X

TOP

¦^´_ 19# ui123
­×§ï¦p¤U¡A¥i§tÃä¤WªºÂI¡A¦³Àu¥ý¶¶§Ç(¾a«eªºÀu¥ý)
°Ï°ì¤£­­ABC¤T°Ï¥i¦b°Ñ¼Æ¦Û¦æ¼W¥[¡A¦ý­n¨Ì°Ñ¼Æ¶¶§Ç¡C
  1. Function pointInPoly(ptx As Double, pty As Double, arPoly) As Boolean
  2.     Dim i As Long, j As Long
  3.     Dim pix As Double, piy As Double
  4.     Dim pjx As Double, pjy As Double
  5.    
  6.     For i = 1 To UBound(arPoly) - 1
  7.         j = i + 1
  8.         pix = arPoly(i, 1): piy = arPoly(i, 2)
  9.         pjx = arPoly(j, 1): pjy = arPoly(j, 2)
  10.         
  11.         '¦hÃä§ÎÃä¤W
  12.         If (pix - ptx) * (pjy - pty) - (piy - pty) * (pjx - ptx) = 0 And _
  13.             (pix - ptx) * (pjx - ptx) + (piy - pty) * (pjy - pty) <= 0 Then _
  14.         pointInPoly = True: Exit Function
  15.         
  16.         '¦hÃä§Î¤º³¡
  17.         If Not (piy > pty) = (pjy > pty) Then
  18.             If ptx < (pjx - pix) * (pty - piy) / (pjy - piy) + pix Then pointInPoly = Not pointInPoly
  19.         End If
  20.     Next
  21. End Function

  22. Function RegionABC(x As Double, y As Double, ParamArray polyRegion())
  23.     '3rd°Ñ¼Æ¬°A°Ï¡A4th°Ñ¼Æ¬°B°Ï¡C¡C¡C¨Ì¦¹Ãþ±À¡A¶V¾a«eªºÀu¥ý¡C
  24.     Dim i As Long, arPoly
  25.         
  26.     For i = LBound(polyRegion) To UBound(polyRegion)
  27.         arPoly = polyRegion(i).Value
  28.         
  29.         If UBound(arPoly, 2) <> 2 _
  30.             Or arPoly(1, 1) <> arPoly(UBound(arPoly), 1) _
  31.             Or arPoly(1, 2) <> arPoly(UBound(arPoly), 2) Then RegionABC = CVErr(xlErrRef): Exit Function
  32.         
  33.         If pointInPoly(x, y, arPoly) Then
  34.             RegionABC = Chr(65 + i - LBound(polyRegion))    '¨Ì¶¶¦ìÅã¥ÜA¡AB¡AC¡AD
  35.             Exit Function
  36.         End If
  37.     Next i
  38.     RegionABC = "¤£¦b½d³ò¤º"
  39. End Function
½Æ»s¥N½X

TOP

¦^´_ 19# ui123
A°Ï­±¿n =PolyArea(C4:D8)
³o¥u¬OML089¤j¦b10¼Ó­n§Ú¥t¥~À°¦£¼gªººâ­±¿nªº¨ç¼Æ¡C

TOP

        ÀR«ä¦Û¦b : ¦a¤WºØ¤Fµæ¡A´N¤£©öªø¯ó¡F¤ß¤¤¦³µ½¡A´N¤£©ö¥Í´c¡C
ªð¦^¦Cªí ¤W¤@¥DÃD