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

[¤À¨É] ¹Bºâ¤lªº­«¸ü

[¤À¨É] ¹Bºâ¤lªº­«¸ü

VB.2005 ¥H¤W¦³¤@¶µ¤£¿ù¥Îªº¥\¯à,¥s¹Bºâ¤lªº­«¸ü
¤°»ò¬O¹Bºâ¤lªº­«¸ü
¨ä¹ê´N¬O¹Bºâ²Å¸¹ªº­«·s©w¸q
³o¦b¼Æ¾Ç¤W«Ü±`¨£
¤@¯ë§Ú­Ì¦b¼Æ¾Ç¤W + - * / ³o¨ÇªF¦è¬O«ü¼Æ¦rªº ¥[´î­¼°£
¦ý¦pªG¨ì¤F¦V¶q,©Î¯x°},©Î¬Oµê¼Æ,³o¨Ç²Å¸¹´N­«·s©w¸q¤F
¦]¬°¦V¶qªº¥[´î­¼°£ªk©M¯Â¶qÅãµM¦³«Ü¤jªº¤£¦P,©Ò¥H
A¦V¶q+B¦V¶qªºµ{¦¡½X¤£·|¼g¦¨ C = A+B
¦ý§Ú­Ì¬°¤F­n¨Ïµ{¦¡½X²³æ©ö©ú¥Õ,©Ò¥H§Ú­Ì¤]«Ü·Q­n³o¼Ë¼g,¨º´N¥²»Ý­«·s©w¸q¹Bºâ¤l

[ <attributes> ] Public [ Overloads ] Shared [ Shadows ] _
[ Widening | Narrowing ] Operator symbol ( operands ) As type
...
End Operator

¨º³o­Ó­n«ç»ò¥Î,§Ú­Ì¥i¥H·s¼W¤@­ÓWindowsForm ±M®×
µM«á¦b¸Ó±M®×¤¤¦A·s¼W¤@­Ó Vector3D Ãþ§O¦p¤U
  1. Public Class Vector3D

  2.     Private mXValue As Double
  3.     Public Property XValue() As Double
  4.         Get
  5.             Return mXValue
  6.         End Get
  7.         Set(ByVal value As Double)
  8.             mXValue = value
  9.         End Set
  10.     End Property

  11.     Private mYvalue As Double
  12.     Public Property YValue() As Double
  13.         Get
  14.             Return mYvalue
  15.         End Get
  16.         Set(ByVal value As Double)
  17.             mYvalue = value
  18.         End Set
  19.     End Property

  20.     Private mZvalue As Double
  21.     Public Property ZValue() As Double
  22.         Get
  23.             Return mZvalue
  24.         End Get
  25.         Set(ByVal value As Double)
  26.             mZvalue = value
  27.         End Set
  28.     End Property

  29.     Public ReadOnly Property NormOfVector() As Double
  30.         Get
  31.             Return Math.Sqrt(XValue * XValue + YValue * YValue + ZValue * ZValue)
  32.         End Get
  33.     End Property

  34.     Public Sub New(ByVal x As Double, ByVal y As Double, ByVal z As Double)

  35.         mXValue = x
  36.         mYvalue = y
  37.         mZvalue = z

  38.     End Sub

  39.     Public Sub New()
  40.         XValue = 0
  41.         YValue = 0
  42.         ZValue = 0
  43.     End Sub

  44.     Public Shared Operator +(ByVal A As Vector3D, ByVal B As Vector3D) As Vector3D

  45.         Return New Vector3D(A.XValue + B.XValue, A.YValue + B.YValue, A.ZValue + B.ZValue)

  46.     End Operator


  47.     Public Shared Operator -(ByVal A As Vector3D, ByVal B As Vector3D) As Vector3D

  48.         Return New Vector3D(A.XValue - B.XValue, A.YValue - B.YValue, A.ZValue - B.ZValue)

  49.     End Operator

  50.     '¥~¿n
  51.     Public Shared Operator *(ByVal A As Vector3D, ByVal B As Vector3D) As Vector3D
  52.         Dim tmpVector As New Vector3D

  53.         With tmpVector
  54.             .XValue = A.YValue * B.ZValue - A.ZValue * B.YValue
  55.             .YValue = -(A.XValue * B.ZValue - A.ZValue * B.XValue)
  56.             .ZValue = A.XValue * B.YValue - A.YValue * B.XValue
  57.         End With
  58.         Return tmpVector
  59.     End Operator


  60.     '¤º¿n
  61.     Public Shared Operator ^(ByVal A As Vector3D, ByVal B As Vector3D) As Double
  62.         Return A.XValue * B.XValue + A.YValue * +B.YValue + A.ZValue * B.ZValue
  63.     End Operator


  64.     Public Shared Function AngleBetweenTwoVector(ByVal A As Vector3D, ByVal B As Vector3D) As Double

  65.         Return Math.Acos((A ^ B) / (A.NormOfVector * B.NormOfVector)) * 180 / Math.PI

  66.     End Function


  67.     Public Overrides Function ToString() As String

  68.         If Me.YValue < 0 And Me.ZValue < 0 Then
  69.             Return Me.XValue & "i - " & -Me.YValue & "j - " & -Me.ZValue & "k"
  70.         End If

  71.         If Me.YValue < 0 And Me.ZValue >= 0 Then
  72.             Return Me.XValue & "i - " & -Me.YValue & "j + " & Me.ZValue & "k"
  73.         End If

  74.         If Me.YValue >= 0 And Me.ZValue < 0 Then
  75.             Return Me.XValue & "i + " & Me.YValue & "j - " & -Me.ZValue & "k"
  76.         End If

  77.         Return Me.XValue & "i + " & Me.YValue & "j + " & Me.ZValue & "k"

  78.     End Function


  79. End Class
½Æ»s¥N½X

¤W­±ªºµ{¦¡½X§Ú­Ì­«©w¸q¤F­¼ªkªº¤º¥~¿n©M¥[´îªk
ÁÙ¦³¤@­Ó¤G¦V¶qªº§¨¨¤¤À¨É¤èªk
¦]¬°¦V¶q¨S¦³°£ªk©Ò¥H¤£¥Î©w¸q,¦Ó­¼ªk¤À¬°¤º¥~¿n¤GºØ
©Ò¥H§Ú­Ì¥i¥H¦b WindowsForm ¤W¼g¤U¥H¤Uµ{¦¡½X
  1. Public Class Form1

  2.     Private A As New Vector3D(2, 3, 2)
  3.     Private B As New Vector3D(1, 2, -1)
  4.     Private C As New Vector3D
  5.     Private D As Double
  6.     Private H As Double

  7.     Private fnt As Font

  8.     Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

  9.         fnt = New Font("·s²Ó©úÅé", 30)

  10.         C = A * B '¥~¿n
  11.         D = A ^ B '¤ºåã
  12.         H = Vector3D.AngleBetweenTwoVector(A, B) '§¨¨¤

  13.     End Sub


  14.     Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

  15.         Dim g As Graphics = e.Graphics

  16.         g.DrawString("¤G¦V¶q¥~¿n¬°   " & C.ToString, fnt, New SolidBrush(Color.Black), 10, 100)
  17.         g.DrawString("¤G¦V¶q¤º¿n¬°   " & D.ToString, fnt, New SolidBrush(Color.Black), 10, 200)
  18.         g.DrawString("¤G¦V¶q§¨¨¤¬°   " & H.ToString & " «×", fnt, New SolidBrush(Color.Black), 10, 300)

  19.     End Sub

  20. End Class
½Æ»s¥N½X
°õ¦æµ²ªG¦p¤U

TOP

¬Ý°_¨Ó¬O¤£¬O¤ñ¸û²Å¦X§Ú­Ì¤@¯ëºâ¼Æ¾Çªº²Å¸¹

¥¼©R¦W.JPG (36.3 KB)

¥¼©R¦W.JPG

1

µû¤À¤H¼Æ

    • Min: ·PÁ±zªº¼ö±¡¤À¨Éª÷¿ú + 3

TOP

        ÀR«ä¦Û¦b : ¥Ç¿ù¥XÄb®¬¤ß¡A¤~¯à²M²bµL·Ð´o¡C
ªð¦^¦Cªí ¤W¤@¥DÃD