Public Function Interf(ByRef Dxa As Double, ByRef Dya
As Double, ByRef Dxb As Double, ByRef Dyb As Double)
As Integer If Dxa = 0 And Dxb = 0 Then Return 1 End If If Dya = 0 And Dyb = 0 Then Return 1 End If If Dxa <> 0 And Dxb <> 0 Then If Dya / Dxa = Dyb / Dxb Then Return 1 End If End If If Dxa = 0 And Dxb <> 0 Then Return 2 End If If Dxb = 0 And Dxa <> 0 Then Return 3 End If Return 4 End Function ----------- X1 = Val(TextBox1.Text) Y1 = Val(TextBox2.Text) X2 = Val(TextBox3.Text) Y2 = Val(TextBox4.Text) X3 = Val(TextBox5.Text) Y3 = Val(TextBox6.Text) X4 = Val(TextBox7.Text) Y4 = Val(TextBox8.Text) Dx1 = (X2 - X1) Dy1 = (Y2 - Y1) Dx2 = (X4 - X3) Dy2 = (Y4 - Y3) sa2 = Interf(Dx1, Dy1, Dx2, Dy2) If sa2 = 1 Then TextBox9.Text = "平行" : TextBox10.Text = "平行" : Exit Sub Else Select Case sa2 Case 2 X5 = X1 : Y5 = (Dy2 / Dx2) * (X5 - X3) + Y3 Case 3 X5 = X3 : Y5 = (Dy1 / Dy2) * (X5 - X1) + Y1 Case 4 X5 = (Y3 - Y1 + (Dy1 / Dx1) * X1 - (Dy2 / Dx2) * X3) / (Dy1 / Dx1 - Dy2 / Dx2) : Y5 = (Dy1 / Dx1) * (X5 - X1) + Y1 End Select End If TextBox9.Text = X5 TextBox10.Text = Y5 |
|