Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi friends ,please help me, i have many rectangles attached with each other on google map, i want to check a point(24.5271348225978,39.5751950517297) is lies inside the all the rectangles or not,
My rectangles latitude and longitude are:
[
((24.571846433888872, 38.904972188566475), (25.006041783055572, 39.06448645904431)),
((24.427114650833303, 39.06448645904431), (25.58496891527784, 39.22400072952214)),
((24.137651084722165, 39.22400072952214), (25.58496891527784, 39.54302927047783)),
((24.137651084722165, 39.54302927047783), (24.861310000000003, 39.702543540955666)),
((24.282382867777734, 39.702543540955666), (24.716578216944437, 39.86205781143352))
] 

please help me
thnx in advance

[edit]Code block added, Urgency deleted - OriginalGriff[/edit]
Posted
Updated 7-Aug-12 19:29pm
v3
Comments
OriginalGriff 26-Jul-12 5:14am    
Urgency deleted: It may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response.

Shouldn't this be done using a loop to go from the first one to the last one checking if the point is inside each rectangle?

Given that your point to be checked is Xp,Yp and you have n rectangles defined by 2 points in a plane (XY): Xr1[n],Yr1[n], Xr2[n],Yr2[n], shouldn't it be as easy as something like:

This is pseudocode to achieve that... probably it is too simple and I've not understood properly your question...
n=1;
bInsideAllOfthem = true;
while bInsideAllOfthem and n <= number_of_rectangles 
do
  bInsideAllOfthem = ((((Xr1[n]-Xp > 0) and (Xr2[n]-Xp < 0)) or ((Xr1[n]-Xp < 0) and (Xr2[n]-Xp > 0))) and 
                     (((Yr1[n]-Yp > 0) and (Yr2[n]-Yp < 0)) or ((Yr1[n]-Yp < 0) and (Yr2[n]-Yp > 0))));
  n++;
end_while


Hope this helps...
 
Share this answer
 
v4
Comments
sjelen 26-Jul-12 6:56am    
Doesn't this work only if rectangles are aligned to X-Y axes?
Arbitrary rectangle in a plane can not be defined with only 2 points.
Joan M 26-Jul-12 7:06am    
Given the fact Pardeep is speaking about latiutude and longitude which are perfectly aligned to the XY axes... and that the only values that Pardeep has shown are 2 pairs for each rectangle... I guess the code will work, taking into account what you point (which would be correct) then we would have to rotate the rectangle in the space and make the check like in my sample, do it using vectors or any other method we could think about...
[no name] 30-Jul-12 4:52am    
hi joan murt thanks for reply but this not work correctly
Joan M 30-Jul-12 4:54am    
why?
[no name] 5-Aug-12 23:51pm    
hi joan murt i can't understand the what value i have to pass into these variable Xr1[n],Yr1[n], Xr2[n],Yr2[n], Please can you explain it bit in details , sorry i have used your code but, i think , i have not use this in correct manner please , explain it, thanks in advance
Here is a good tip:
Is a Point inside a Polygon?[^]
It's meant to work in 2D plane, but it will serve the purpose if you don't need high precision.
The same algorithm can be applied to spherical geo-coordinates, but it includes a lot of trigonometry and is a lot slower.
http://en.wikipedia.org/wiki/Point_in_polygon[^]
P.S.: Here is a another good example:
Classes for computational geometry[^]
The CPolygon class has PointIn method.
 
Share this answer
 
v2
Comments
[no name] 30-Jul-12 4:52am    
thanks for solution
[no name] 5-Aug-12 23:52pm    
sorry , but by this they pick the all the point placed from the right of reactangles

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900