1 Attachment(s)
[RESOLVED] X Marks the Spot / Position an Image Exactly Outside a Picturebox
Hello everybody,
Please look at the attached image to understand my question.
I have 1 Main PictureBox. Inside that PictureBox is a second PictureBox (picCircle) with a Circle and a Line Object (LQ) from the Center to the edge of the circle. In the First PictureBox I also have an Image (imgDirection) (the Yellow X) and a black circle.
Here is my question. The line (LQ) in the center of the circle can move to any degree between 0 and 360. I want to position the Image (imgDirection) exactly to where the line is pointing AND remain outside the black circle. Currently I am doing this by trial and error and this is what I came up with which seems Ok but is there a better and exact way? Thanks for any assistance.
Code:
Select Case dblDirection
Case -180 To -150
imgDirection.Left = (picCircle.ScaleWidth / 2) + LQ.X2
imgDirection.Top = (picCircle.ScaleHeight / 2) + 1.3 * LQ.Y2
Case -150 To -110
imgDirection.Left = (picCircle.ScaleWidth / 2) + 1.3 * LQ.X2
imgDirection.Top = (picCircle.ScaleHeight / 2) + 1.2 * LQ.Y2
Case -110 To -30
imgDirection.Left = (picCircle.ScaleWidth / 2) + 1.3 * LQ.X2
imgDirection.Top = 1.5 * LQ.Y2
Case -30 To -10
imgDirection.Left = (picCircle.ScaleWidth / 2) + 1.1 * LQ.X2
imgDirection.Top = 1.5 * LQ.Y2
Case -10 To 45
imgDirection.Left = 1.5 * LQ.X2
imgDirection.Top = 1.2 * LQ.Y2
Case 45 To 100
imgDirection.Left = LQ.X2
imgDirection.Top = 1.5 * LQ.Y2
Case 100 To 165
imgDirection.Left = 1.1 * LQ.X2
imgDirection.Top = (picCircle.ScaleHeight / 2) + 1.3 * LQ.Y2
Case 165 To 190
imgDirection.Left = (picCircle.ScaleWidth / 2) + LQ.X2
imgDirection.Top = (picCircle.ScaleHeight / 2) + 1.3 * LQ.Y2
End Select
Re: X Marks the Spot / Position an Image Exactly Outside a Picturebox
Some ideas and questions:
-1-
According to your: "I want to position the Image (imgDirection) exactly to where the line is pointing AND remain outside the black square." The imgDirection should be just ouside the black square, but in your code you put in relation to the picCircle? Which is correct? From my point of view the picture attached is not corresponding to the code posted!
-2-
Calculate the center of your imgdirection using the direction of your line (I think you have that as dblDirection). With the line you had a fixed length all the time, in here you need the length to be a functiion of the direction. If you are using he degree-system 0 or 360 is North(to the top) 90 is East(to the left).
All angles between 315 and 045 use a fixed Top (Top of black square - half height of imgDirection) and a calculated Left (Left of black square +((half of (width blacksquare +width of imgDirection)*tan(direction))
All angles between 45 and 135 use a calculate Top (Top of black square - ((half of (heigthof blacksquare +heigth of imgDirection)*cotan(direction)) and a fixed Left (Left of black square +half of width of imgDirection) ... and so forth
Note check the + and -, they migth be to the wrong side, I justed typed that one in!
Re: X Marks the Spot / Position an Image Exactly Outside a Picturebox
You cheated, you changed the threat while I was writing an answer on the original text. Now you have a black circle insted of the black box. That would be fairly simple, you have the distance fixed (calculated from the centre of all your circles), so use the same routine that calculated the endpoint of the line to calculate the center point of your imgDirection!
Re: X Marks the Spot / Position an Image Exactly Outside a Picturebox
Hello Opus, thank you for your input. Sorry I edited my post a few minutes after writing it as I realized that a circle would be easier then a square. In any case the black circle is just for distance purpose in the final result it will be invisible.
How would I calculate the .Left and .Top of the imgDirection once I calculate that distance? As the endpoint of the line is the radius with an angle inside a picturebox. However the coordinates I need is for the imgDirection which is .Left amd .Top. Any ideas?
Re: X Marks the Spot / Position an Image Exactly Outside a Picturebox
I would consider the calculated points as the center of the imgDirection (if you used the radius of that circle + half the width of imgDirection. The .Left and the .Top will then be just a fixed offset to the calculated point ( -0.5*Heigth and -0.5*Width).
Re: X Marks the Spot / Position an Image Exactly Outside a Picturebox
Thank you opus for your assistance. In the end this was my solution for all angles, I multiply by a factor and it gives me the result I want.
Code:
imgDirection.Left = 2 * LQ.X2
imgDirection.Top = 2 * LQ.Y2