Home > Enterprise >  Detecting when bounds of a rotating circle have hit a square
Detecting when bounds of a rotating circle have hit a square

Time:12-03

I am having trouble attempting to detect when a circle, that is following a point in a circle, has hit a label. When it hits the label, I want the label to go to the top right of the screen. So far, it will draw the circle, and it goes around the point forever, but its going right through the label, without the label being moved to the top left. Here's my code.

    Public Sub circleDetection(circle As Rectangle)
        If Label1.Bounds.IntersectsWith(circle) Then
            Label1.Top = 0
            Label1.Left = 0
            MsgBox("you DIED!")
        End If
    End Sub

Private WithEvents TMcircle As New Timer
    Dim SunCentre As New Point(300, 300)
    Dim OrbitRadius As Integer = 150
    Dim PlanetDiameter As Integer = 10
    Dim Planet As New Rectangle(OrbitRadius - PlanetDiameter \ 2, PlanetDiameter \ 2, PlanetDiameter, PlanetDiameter)
    Dim Angle As Single
    Private Sub Tmr_Tick(sender As Object, e As System.EventArgs) Handles TMcircle.Tick
        Angle  = 1
        Invalidate()
        circleDetection(Planet)
    End Sub
    Public Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        ' draw center
        e.Graphics.TranslateTransform(SunCentre.X, SunCentre.Y)
        ' draw circle
        e.Graphics.RotateTransform(Angle)
        e.Graphics.FillEllipse(Brushes.Blue, Planet)
    End Sub

I have attempted to draw a secondary circle where the angle leads to, but this has failed to work as I do not have the x and y coordinates of the rotated circle. It didn't fail to run, but nothing showed up no matter how big I made it.

CodePudding user response:

You use the enter image description here

  • Related