English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

various objects within the associated applet, to display the name of the object that the click is nearest to, for example?

I think all the objects' x and y coordinates have to be stored in arrays, to be calculated against with the coordinates of the x,y of the mouse clicks?

2007-03-06 22:13:49 · 3 answers · asked by hippyJu 4 in Science & Mathematics Mathematics

3 answers

I'm no java expert, so I can't help you with the details, but that seems about right. You'll certainly need a list of all though objects positions, so computing root[(x1-x2)^2 + (y1-y2)^2] and picking the minimum shouldn't be too much extra effort.

One possible alternative would be to map out the screen beforehand, and say that if the mouse click is in *this* region then *this* is the closest object. That could get a bit messy of you've got lots of randomly distributed objects, but if you have only a few, or they are in some sort of regular grid, it might be an option.

If the objects are in a regular grid, then it would be easy enough to work out which object is closest without calculating the relevent distances.

One final thing to consider is whether your objects are points, circles or some other shape - in the first two cases you're fine, just say the object is at the point, or the centre of the circle. Otherwise things might get complicated - consider a long thin rectangle. Then clicking at the end would be a long way from the 'centre' of the rectangle, but is clearly close to the body of the rectangle.

2007-03-06 22:40:39 · answer #1 · answered by robcraine 4 · 0 0

calculate the square of the distance between the point and each of the objects.
(x-a)^2 + (y-b)^2 where (x,y) is the coordinate of the point and (a,b) for the object. whichever has the minimum value for this expression is the nearest object.

2007-03-06 22:32:27 · answer #2 · answered by FedUp 3 · 0 0

5/9 of the radius of the Earth. that is assuming that factors are chosen randomly in accordance to the following set of guidelines: We take a dice which precisely encloses the Earth and choose factors uniformly from interior that dice. If the point chosen is outside the Earth, it truly is rejected and this procedure is repeated until eventually a level interior or on the earth is selected. that is the first aspect. This technique is repeated interior an identical thanks to pick the 2d aspect.

2016-12-05 08:54:10 · answer #3 · answered by ? 4 · 0 0

fedest.com, questions and answers