Not Yet Answered # Python Join points to a square

jrcagle 77 jrcagle 77 bboho Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...

0

Well, there are several parts to this.

First, you need to be able to read and respond to the mouse click. That happens by binding your mouse events to your window.

Then, you need to specify your problem more clearly. If you want to draw a line segment from the mouse to the center of the square, then you only need to know how to draw a line segment.

But if you want to draw from the mouse to the nearest corner of the square, then you'll need to compute whichever corner is closest, and then draw.

Or if you want to draw from the mouse to the nearest *point* on the square, then you'll need to do some fancy-schmancy coordinate geometry, and then draw.

So: which problem are you trying to solve?

Jeff

0

Well sure, just pick the hardest one, then.

Here's the plan in general terms. You might want to draw it on paper.

* Divide up your canvas into nine (imaginary) sectors by extending the sides of the square. The whole thing looks like a tic-tac-toe board. Number the sectors 0 - 8.

* If the point is in sectors 0, 2, 6, or 8, then the closest point is one of the corners of the square.

* Elif the point is in sectors 1, 3, 5, or 7, then the closest point is straight down, right, left, or up (respectively).

* Else the point is inside the square, and you might have to do trial and error.

Here's a concrete example: Let the corners of your square be (100,100); (200,100); (100,200); (200,200).

Then the method above applied to the following points yields:

(5,20) --> connect to (100,100) (sector 0)

(150,20) --> connect to (150,100) (sector 1)

(300,150) --> connect to (200,150) (sector 5)

(120,175) --> try (120,100), (100,175), (120,200), (200,175). Closest fit is (120,200).

IF your squares are all aligned with sides parallel to the axes, then you can use inequalities to determine the sector:

```
if point.x < square.left and point.y < square.top:
#sector 0
etc.
```

Hope it helps,

Jeff

0

Not all points in a square add up to give you 90 degrees.

' The time to wither and die is greatest at dawn, for you have everything to live for.'

Euclid

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.

btn_addline :

`Private Sub btn_addline_Click(ByVal ...`

I don’t want at this stage work on a big separate project as I've already got plenty ...