B
B
bio2016-04-19 15:13:52
JavaScript
bio, 2016-04-19 15:13:52

How to find out which side an element is closer to when dragging and dropping?

There is a block 8d9b888822.png, when dragging a round block, you need to highlight the side to which it is closer.
Tell me how to implement it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
ManWithBear, 2016-04-19
@bioforge

What perversions?
origin - bottom left corner (0;0)
to left side - abs(center.x)
to right side - abs(width-center.x)
to bottom side - abs(center.y)
to top side - abs(height- center.y) You
can compare 4 numbers :)
The option above will not work unsquared and requires 4 sqrt and 8 squaring.

G
GreatRash, 2016-04-19
@GreatRash

1) We know the center of the circle
2) We know the middle of each side of the block
3) We measure the distance from the center of the circle to the center of each side
4) Which distance is less, the circle is closer there
UPD: confused

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question