私はこれを何日も続けています。
私は数学的に (PQ 式と Qaudratic 方程式を使用して) 直線と曲線の交点を得ることができました。しかし、このポイントは、フォームのこのポイントまでマウスクリックしたときに得られるポイントとは異なります。
以下はスクリーンショットです: http://s7.directupload.net/file/d/3341/zi8ohv7u_png.htm "msgMouseClickOnPoint"
また、私のコードの一部
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
Dim ptLocationOnForm As New System.Drawing.Point
'To get the mouse location relative to the Form
ptLocationOnForm = Me.PointToClient(Cursor.Position)
'SHow the locations
MessageBox.Show(ptLocationOnForm.X.ToString + " : " + (ptLocationOnForm.Y).ToString)
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
'' Create font and brush.
Dim drawFont As New Font("Arial", 8)
Dim drawBrush As New SolidBrush(Color.Black)
Dim x1 As Integer = 0
Dim y1 As Integer = 100
Dim x2 As Integer = 500
Dim y2 As Integer = 250
' y = m*x +b
' m = (y1-y2)/(x1-x2)
' b = y1 -m*x1
Dim m As Double = (y1 - y2) / (x1 - x2)
Dim b As Double = y1 - (m * x1)
'Testing m and b
'y1 = m * x1 + b
'y2 = m * x2 + b
Dim g As Graphics
Dim p As Pen
p = New Pen(System.Drawing.Color.Black)
Dim px = New Pen(System.Drawing.Color.DarkOrange)
g = e.Graphics
With g
'draw x Axis
.DrawLine(p, 0, 500, 500, 500)
'draw y Axis
.DrawLine(p, 0, 0, 0, 500)
'draw marks on the Axis
.DrawLine(px, 100, 495, 100, 505)
.DrawLine(px, 200, 495, 200, 505)
.DrawLine(px, 300, 495, 300, 505)
.DrawLine(px, 400, 495, 400, 505)
.DrawLine(p, 0, 100, 10, 100)
.DrawLine(p, 0, 200, 10, 200)
.DrawLine(p, 0, 300, 10, 300)
.DrawLine(p, 0, 400, 10, 400)
.DrawLine(New Pen(System.Drawing.Color.DarkGreen), x1, y1, x2, y2)
.DrawString(x2.ToString + ", " + (y2).ToString, drawFont, Brushes.Brown, x2, y2)
.DrawString(x1.ToString + ", " + (y1).ToString, drawFont, Brushes.Brown, x1, y1)
.DrawString("Line Equation: " + (m).ToString + "X² + " + b.ToString, drawFont, Brushes.Brown, 189, 140)
End With
'draw curve
Dim xc1 As Integer = 20
Dim yc1 As Integer = 120
Dim xc2 As Integer = 240
Dim yc2 As Integer = 489
Dim xc3 As Integer = 500
Dim yc3 As Integer = 20
Dim point1 As New Point(xc1, yc1)
Dim point2 As New Point(xc2, yc2)
Dim point3 As New Point(xc3, yc3)
Dim points() As Point = {point1, point2, point3}
'Draw Curve before calculating a, bc and c. This helps to test the correctness of a, bc and c.
e.Graphics.DrawCurve(Pens.Green, points)
'calculate a, bc anc c
Dim a As Double = ((yc2 - yc1) * (xc1 - xc3) + (yc3 - yc1) * (xc2 - xc1)) / ((xc1 - xc3) * ((xc2 ^ 2) - (xc1 ^ 2)) + (xc2 - xc1) * ((xc3 ^ 2) - (xc1 ^ 2)))
Dim bc As Double = ((yc2 - yc1) - a * ((xc2 ^ 2) - (xc1 ^ 2))) / (xc2 - xc1)
Dim c As Double = yc1 - (a * (xc1 ^ 2)) - (bc * xc1)
e.Graphics.DrawString("Curve Equation: Ax² + Bx + C := " + a.ToString + " X² + " + bc.ToString + " X + " + c.ToString, drawFont, Brushes.Green, 100, 10)
'create another y points using Curve Equation
yc1 = a * (xc1 ^ 2) + (bc * xc1) + c
yc2 = a * (xc2 ^ 2) + (bc * xc2) + c
yc3 = a * (xc3 ^ 2) + (bc * xc3) + c
Dim point1_n As New Point(xc1, yc1)
Dim point2_n As New Point(xc2, yc2)
Dim point3_n As New Point(xc3, yc3)
Dim points_n() As Point = {point1_n, point2_n, point3_n}
'Another curve using the new y values. To show that a, bc, c are correct the two curves have to be on eachother
e.Graphics.DrawCurve(Pens.DarkBlue, points_n)
'intercept mit PQ Formel (-p/2 +- wurzel (p/2)^2 - q)
'In other to use the PQ Formula, we need the equation in this form x²+bx+c for the equations: ax²+bcx+c = mx+b
'So solving that equation we will get x² + ((bc-m)/a)x + (c-b)/a
Dim p_inter As Double = (bc - m) / a
Dim q_inter As Double = (c - b) / a
'e.Graphics.DrawString("a : " + a.ToString + ", b : " + (bc - m).ToString + ", c : " + (c - b).ToString, drawFont, Brushes.Brown, 25, 600)
'e.Graphics.DrawString("p = " + p_inter.ToString + ", q = " + q_inter.ToString, drawFont, Brushes.Brown, 25, 620)
Dim unterWurzel As Double = ((p_inter / 2) ^ 2) - q_inter
Dim x_positive As Double = -(p_inter / 2) + (Math.Sqrt(unterWurzel))
'substituting the x in the line Equation to get the corresponding y
Dim y_positive As Double = m * x_positive + b
e.Graphics.DrawString("Points of interception", drawFont, Brushes.Brown, 400, 285)
e.Graphics.DrawString("( " + x_positive.ToString + " , " + (y_positive).ToString + " )", drawFont, Brushes.Brown, 400, 300)
Dim x_negative As Double = -(p_inter / 2) - (Math.Sqrt(unterWurzel))
Dim y_negative As Double = m * x_negative + b
'also substituting in the curve Equation give the same value
Dim y_equa_nega As Double = a * (x_negative ^ 2) + (bc * x_negative) + c
Dim y_equa_pos As Double = a * (x_positive ^ 2) + (bc * x_positive) + c
'e.Graphics.DrawString("Y(Negative) from Curve : " + (Trans - y_equa_nega).ToString, drawFont, Brushes.Brown, 25, 555)
'e.Graphics.DrawString("Y(positive) from Curve : " + (Trans - y_equa_pos).ToString, drawFont, Brushes.Brown, 25, 575)
e.Graphics.DrawString("( " + x_negative.ToString + " : " + (y_negative).ToString + " )", drawFont, Brushes.Brown, 400, 325)
End Sub
計算から取得した値は、そのポイントをマウスでクリックした値と同じではありません。
私はできる限りのことをしましたが、値が同じでない理由はまだわかりません。
助けてください。
ありがとう