Dear Friends,
This is my first question here, so please be gentle :)
I am working on a VS2010 vb.net winform application. The form has one big picturebox (Picturebox1) and dynamically created small numbers of picturebox, named pin_00, pin_01 ... pin_nn, scattered around. The small picturebox has an image a small circle which is 14x14 in size and the small picturebox's sizeMode is set to AutoSize
The main aim is to draw a line from one pin to another with a line (ArrowAnchor caps) on picturebox. The line arrow acnchor head must point to the center of the small circle, which i have accomplished.
The problem is when the line is drawn, the Arrow Anchor Head (since the line extends up to the center of the small picturebox) is hidden by the small picturebox
Now, what i want is to make the line reach only to the circumference of the circle, so that the arrow head will be visible and still point to the center of the small picturebox.
I know that the solution is just plain circle and line equation finding the point of intersection. But i cant make it right. Please help.
Here is the code i have tried:
Dim mPen As Pen = New Pen(Brushes.RoyalBlue, 2)
mPen.EndCap = Drawing2D.LineCap.ArrowAnchor
gr = Graphics.FromImage(PictureBox1.Image)
Dim p1 As Point = New Point(startPIN.Location.X + (startPIN.Width / 2), _
startPIN.Location.Y + (startPIN.Height / 2))
Dim p2 As Point = New Point((endPIN.Location.X + (endPIN.Width / 2)), _
(endPIN.Location.Y + (endPIN.Height / 2)))
Dim pinRadius As Integer = endPIN.Width / 2
Dim m As Single = (p2.Y - p1.Y) / (p2.X - p1.X)
p2 = New Point(p2.X + (pinRadius / Math.Sqrt(1 + (m ^ 2))), p2.Y + (pinRadius / Math.Sqrt(1 + (1 / (m ^ 2)))))
gr.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
Dim gpath As New Drawing2D.GraphicsPath
gpath.AddLine(p1, p2)
gr.DrawPath(mPen, gpath)
gr.FillPath(bbrush, gpath)
PictureBox1.Refresh()
I have searched on google but cant find anything more than how to use line and circle equation. Did i miss something or my deduced point of intersection formula is wrong?
here is a pic link of how i want and what i get so far
http://tinypic.com/r/2pziudl/5[
^]