# Problem: If a picturebox intersects with a specific area of another.

Page 1 of 1

## 7 Replies - 2118 Views - Last Post: 16 December 2011 - 03:41 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=259563&amp;s=736dad7e28740176aef2e77a58245a7c&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Banksy

Reputation: 0
• Posts: 11
• Joined: 10-July 11

# Problem: If a picturebox intersects with a specific area of another.

Posted 12 December 2011 - 10:45 AM

What I'm trying to do (for a pong game), is what the original creator of pong did. What he did was, he divided the paddle into eight segments to change the ball's angle of return. Now I only want 3 as it's more simplistic, among other reasons. But my problem is, getting to see if the ball intersects with an area of another picturebox.

My user's picturebox has a height of 120, so I want to see if the ball picturebox intersects with the area of the user's picturebox's height to the user's picturebox's height - 40.

I know that was probably a really, really confusing question, because even I confused myself. If you need more details, I'll be happy to supply them.

Is This A Good Question/Topic? 0

## Replies To: Problem: If a picturebox intersects with a specific area of another.

### #2 modi123_1

• Suitor #2

Reputation: 10835
• Posts: 42,418
• Joined: 12-June 08

## Re: Problem: If a picturebox intersects with a specific area of another.

Posted 12 December 2011 - 11:02 AM

Yeah.. not a hundred percent sure what you are asking for. Can you throw us a quick image of what you want done?

### #3 _HAWK_

• Master(Of Foo)

Reputation: 1159
• Posts: 4,440
• Joined: 02-July 08

## Re: Problem: If a picturebox intersects with a specific area of another.

Posted 12 December 2011 - 11:03 AM

You can check the PB.ClientRectangle.IntersectWith(<another rectangle>). You could also do the whole thing with rectangles and no PB's if you wanted a bit more challenge later. Kind of a pure graphics version. Sorry I am a huge graphics guy.

### #4 Banksy

Reputation: 0
• Posts: 11
• Joined: 10-July 11

## Re: Problem: If a picturebox intersects with a specific area of another.

Posted 14 December 2011 - 10:15 AM

_HAWK_, on 12 December 2011 - 11:03 AM, said:

You can check the PB.ClientRectangle.IntersectWith(<another rectangle>). You could also do the whole thing with rectangles and no PB's if you wanted a bit more challenge later. Kind of a pure graphics version. Sorry I am a huge graphics guy.

The problem is not getting it intersecting with another rectangle, but getting it to intersect with a specific part of that triangle.

Basically, I want to see if the pong ball intersects with the part of the user's paddle that i made a square around.

Also, sorry for the late reply. I've been really busy lately.

### #5 _HAWK_

• Master(Of Foo)

Reputation: 1159
• Posts: 4,440
• Joined: 02-July 08

## Re: Problem: If a picturebox intersects with a specific area of another.

Posted 14 December 2011 - 12:43 PM

That would be a math thing. Once you have determined they have connected you figure out where it struck the paddle.

This post has been edited by _HAWK_: 14 December 2011 - 07:43 PM

### #6 Banksy

Reputation: 0
• Posts: 11
• Joined: 10-July 11

## Re: Problem: If a picturebox intersects with a specific area of another.

Posted 16 December 2011 - 10:34 AM

_HAWK_, on 14 December 2011 - 12:43 PM, said:

That would be a math thing. Once you have determined they have connected you figure out where it struck the paddle.

I know that's what I need to do, however I don't know how to do it.

### #7 _HAWK_

• Master(Of Foo)

Reputation: 1159
• Posts: 4,440
• Joined: 02-July 08

## Re: Problem: If a picturebox intersects with a specific area of another.

Posted 16 December 2011 - 11:16 AM

Logic:

1) detect collision, skip all if false
2) variable to hold the the paddle top integer
3) create the zones of the paddle -> height / number of zones
4) determine the middle of the ball rect - integer variable,
5) loop thru the number of zones where you test the lower and upper numbers and if the middle variable is between them
6) apply the angle base on which zone returned a true result

Loop(the harder part):

```Dim zoneTop As Integer = paddleTop
For z As Integer = 1 To zoneCount
Select Case z
Case 1 'top
If ballMiddle < zoneTop + zoneHt Then
End If
Case 2 To zoneCount - 1
If ballMiddle > zoneTop AndAlso < zoneTop + zoneHt
'adjust angle for a middle zone
End If
Case zoneCount
If ballMiddle > zoneTop + zoneHt
End If
End Select
zoneTop += zoneHt 'increment the zone ht
Next
```

You still need to create the variable above - just an example.

This post has been edited by _HAWK_: 16 December 2011 - 11:21 AM

### #8 DimitriV

• vexing conundrum

Reputation: 587
• Posts: 2,746
• Joined: 24-July 11

## Re: Problem: If a picturebox intersects with a specific area of another.

Posted 16 December 2011 - 03:41 PM