Point of interception of a Line with Curve vb.net -
i have been on days now.
i have mathematically (using pq formula , qaudratic equation) managed point of interception of curve line. point not same point when mouse-click point form.
below screenshot: http://s7.directupload.net/file/d/3341/zi8ohv7u_png.htm "msgmouseclickonpoint"
also, part of code
private sub form1_mouseclick(byval sender object, byval e system.windows.forms.mouseeventargs) handles me.mouseclick dim ptlocationonform new system.drawing.point 'to mouse location relative form ptlocationonform = me.pointtoclient(cursor.position) 'show locations messagebox.show(ptlocationonform.x.tostring + " : " + (ptlocationonform.y).tostring) end sub private sub form1_paint(byval sender object, byval e system.windows.forms.painteventargs) handles me.paint '' create font , brush. dim drawfont new font("arial", 8) dim drawbrush new solidbrush(color.black) dim x1 integer = 0 dim y1 integer = 100 dim x2 integer = 500 dim y2 integer = 250 ' y = m*x +b ' m = (y1-y2)/(x1-x2) ' b = y1 -m*x1 dim m double = (y1 - y2) / (x1 - x2) dim b double = y1 - (m * x1) 'testing m , b 'y1 = m * x1 + b 'y2 = m * x2 + b dim g graphics dim p pen p = new pen(system.drawing.color.black) dim px = new pen(system.drawing.color.darkorange) g = e.graphics g 'draw x axis .drawline(p, 0, 500, 500, 500) 'draw y axis .drawline(p, 0, 0, 0, 500) 'draw marks on 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 'draw curve dim xc1 integer = 20 dim yc1 integer = 120 dim xc2 integer = 240 dim yc2 integer = 489 dim xc3 integer = 500 dim yc3 integer = 20 dim point1 new point(xc1, yc1) dim point2 new point(xc2, yc2) dim point3 new point(xc3, yc3) dim points() point = {point1, point2, point3} 'draw curve before calculating a, bc , c. helps test correctness of a, bc , c. e.graphics.drawcurve(pens.green, points) 'calculate a, bc anc c dim double = ((yc2 - yc1) * (xc1 - xc3) + (yc3 - yc1) * (xc2 - xc1)) / ((xc1 - xc3) * ((xc2 ^ 2) - (xc1 ^ 2)) + (xc2 - xc1) * ((xc3 ^ 2) - (xc1 ^ 2))) dim bc double = ((yc2 - yc1) - * ((xc2 ^ 2) - (xc1 ^ 2))) / (xc2 - xc1) dim c 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 y points using curve equation yc1 = * (xc1 ^ 2) + (bc * xc1) + c yc2 = * (xc2 ^ 2) + (bc * xc2) + c yc3 = * (xc3 ^ 2) + (bc * xc3) + c dim point1_n new point(xc1, yc1) dim point2_n new point(xc2, yc2) dim point3_n new point(xc3, yc3) dim points_n() point = {point1_n, point2_n, point3_n} 'another curve using new y values. show a, bc, c correct 2 curves have on eachother e.graphics.drawcurve(pens.darkblue, points_n) 'intercept mit pq formel (-p/2 +- wurzel (p/2)^2 - q) 'in other use pq formula, need equation in form x²+bx+c equations: ax²+bcx+c = mx+b 'so solving equation x² + ((bc-m)/a)x + (c-b)/a dim p_inter double = (bc - m) / dim q_inter double = (c - b) / '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 double = ((p_inter / 2) ^ 2) - q_inter dim x_positive double = -(p_inter / 2) + (math.sqrt(unterwurzel)) 'substituting x in line equation corresponding y dim y_positive 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 double = -(p_inter / 2) - (math.sqrt(unterwurzel)) dim y_negative double = m * x_negative + b 'also substituting in curve equation give same value dim y_equa_nega double = * (x_negative ^ 2) + (bc * x_negative) + c dim y_equa_pos double = * (x_positive ^ 2) + (bc * x_positive) + c 'e.graphics.drawstring("y(negative) curve : " + (trans - y_equa_nega).tostring, drawfont, brushes.brown, 25, 555) 'e.graphics.drawstring("y(positive) 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 the values calculation not same value mouse-click on point.
i have done still dont know why values not same.
pls me.
thanks
Comments
Post a Comment