Hi,
I know this is slightly OT but before i can get to the programming part i
want to make sure that i have the structure covered.
I have a 2D map and items in my list/vector will be lines on the map, with a
start and finish point within the map, so an item would have a start pos
S(x,y) and an end pos E(x,y).
so my structure would be something like
struct _POS{
int x;
int y;
};
struct _ITEMLOC{
_POS pos_start;
_POS pos_end;
};
So in effect it would be a straight line going from one point to another.
If i have a vector with hundreds of items i want to retrieve all the items
that fall within a certain square.
something like Search( top, left, bottom, right). And that would return all
the items whose line are within that square, (either partially or totally).
Does anybody know how i could achieve that?
Many thanks in advance.
Sims
Jul 22 '05
14 1633
"Karl Heinz Buchegger" <kb******@gasca d.at> skrev i en meddelelse
news:40******** *******@gascad. at... Jerry Coffin wrote: In article <bu************ @ID-162430.news.uni-berlin.de>, si*********@hot mail.com says...
[ ... ]
Thanks for the replies, The elements are created once, there is no delete or insert afterward.
In that case, you almost certainly want to use a vector rather than a set or map -- the latter offer logarithmic time on insertions and deletions, but in exchange for this, they normally lose some searching speed (at least on most processors).
But still sorting the squares eg. on the left x-coordinate can speed up the process. The reason is simple: Walking linearly through the vector and testing the primitiv against it, once you found a square, which has a left x-coordinate greater then the maximum x coordinate of the primitive (lies entirely to the right of the primtive) you know that all other squares will also be completely right of the primtive and thus the test can be terminated early.
But as always: profile, if it makes a difference. Especially with computer graphics it's not always obvious where the time is spent.
-- Karl Heinz Buchegger kb******@gascad .at
The actual problem - as I understood it - was to draw all lines found in
some square. In that case, sorting would be almost useless so far as i can
see.
Kind regards
Peter
Peter Koch Larsen wrote:
The actual problem - as I understood it - was to draw all lines found in some square. In that case, sorting would be almost useless so far as i can see.
Aehm. Somehow I turned this around to read: some lines against
lots of squares :-)
Anyway:
Sort the lines by their minumum x coordinate. You can stop
testing the lines as soon as you find one which has a minumum
x coordinate which is bigger then the maximum x coordinate of
the square.
--
Karl Heinz Buchegger kb******@gascad .at
"Jerry Coffin" <jc*****@taeus. com> wrote in message
news:MP******** *************** *@news.clspco.a delphia.net...
[SNIP] For frequent searches, I'd instead represent the points in polar coordinates, and convert the corners of the rectangle to polar coordinates as well.
If I understand you correctly you try to eliminate the vast majority of
candidates by testing whether they fall into that "slice". In case they do
you perform the actual test whether the point is within the square. In
principle this means that you perform a projection onto the angular
coordinate to perform the coarse test. However, I don't really understand
the advantage resulting from the conversion to polar coordinates, as such
projection tests (based on cartesian coordinates) are a common technique in
collision detection. The number of minum comparisons is 1 and the maximum
number of comparisons is 2. IMHO it's just the same with the polar
coordinates, but probably I'm missing something. I'd really appreciate if
you could point out whether I'm overlooking some crucial point.
Regards
Chris
"Karl Heinz Buchegger" <kb******@gasca d.at> skrev i en meddelelse
news:40******** *******@gascad. at... Peter Koch Larsen wrote:
The actual problem - as I understood it - was to draw all lines found in some square. In that case, sorting would be almost useless so far as i
can see.
Aehm. Somehow I turned this around to read: some lines against lots of squares :-)
Anyway: Sort the lines by their minumum x coordinate. You can stop testing the lines as soon as you find one which has a minumum x coordinate which is bigger then the maximum x coordinate of the square.
-- Karl Heinz Buchegger kb******@gascad .at
Yes. This will help the filtering somewhat, but if it pays of is another
question. My gut feeling is that sorting and searching will not help much
unless it is quite accurate and that a simple sorting on max x-coordinate
will be close to useless. There are no doubt better ways to do it but then
we should be in comp.programmin g or perhaps comp.database.t heory (my
subconsiousness says Hilbert-curves could be interesting here).
Kind regards
Peter
Peter Koch Larsen wrote:
Yes. This will help the filtering somewhat, but if it pays of is another question. My gut feeling is that sorting and searching will not help much unless it is quite accurate and that a simple sorting on max x-coordinate will be close to useless.
That depends on how often the whole process is done, how often the
lines are updated etc. It can make a difference but often it is just
the case that the sort process takes longer then testing a few thousend
lines against a box (which is quite simple to do, especially if the lines
can be reoriented to always point eg. to the right and up).
That's why I said in a previous post: Try it and see if it makes a
difference.
There are no doubt better ways to do it but then we should be in comp.programmin g or perhaps comp.database.t heory (my subconsiousness says Hilbert-curves could be interesting here).
comp.graphics.a lgorithms
--
Karl Heinz Buchegger kb******@gascad .at This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Darryl B |
last post by:
I can not get anywhere on this project I'm tryin to do. I'm not
expecting any major help with this but any would be appreciated. The
assignment is attached. The problem I'm having is trying to set up the
class link and tel_list. I set up a class person with strings for
name, town, and number. I just don't know how to set up the classes w/
their methods (constructors and operations). I'm stuck on the
assignment operator and the add and...
|
by: Glen Able |
last post by:
Hi,
I have a collection of lists, something like this:
std::list<Obj*> lists;
Now I add an Obj to one of the lists:
Obj* gary;
lists.push_front(gary);
|
by: msnews.microsoft.com |
last post by:
I'd like to hear your thoughts on best methods for populating drop down list
controls. I have states and countries drop down lists that don't change
often, so naturally I "hard code" them in the aspx page. But the problem is
these tend to really slow the development -- it takes up to 15 seconds for
the page to come up in VS.NET design environment, so I'm thinking about
taking these out and populating the controls dynamically using the...
|
by: David Freeman |
last post by:
Hi There!
I'm trying to create a User Registration page in ASP.NET and wondering what
is the best way to get the list of up-to-date Countries and Cities? Are
there any Web Services on the web that I can use to retrieve such
information? If not, what are the options?
Please, any suggestions and pointers will be very much appreciated!
Dave
|
by: Andrew |
last post by:
I have created a Component called a BOConnector that implements IBindingList
so it can provide access to a list of business objects to be bound to
controls.
At design time there is no live list of objects so BOConnector creates an
internal list of one object. It needs one object because when you bind to a
grid etc at design time it needs to get a list of properties to make the
columns.
My BOConnector works just fine with grids and...
| |
by: 2005 |
last post by:
Hi
In C++, are the following considered best practices or not?
- passing aguments to functions (ie functions do not take any arguments
)
- returning values using return statement
Anything else?
The reason for this question is that I had an assignment in which I was
|
by: joshc |
last post by:
In an interview for an embedded software position recently I was asked
to write code, in C, for printing the contents of a linked list
backwards. After a few minutes I came up with the recursive solution.
Being that recursion is frowned upon in embedded software, the answer
was not what the interviewer expected, but alas it was correct. I asked
some friends how they would have answered and another answer is to
reverse the list and then...
|
by: Paul |
last post by:
Hi,
I feel I'm going around circles on this one and would appreciate some other
points of view.
From a design / encapsulation point of view, what's the best practise for
returning a private List<as a property.
Consider the example below, the class "ListTest" contains a private "List<>"
called "strings" - it also provides a public method to add to that list,
|
by: Paul Hadfield |
last post by:
I'm looking for thoughts on the "correct" design for this problem (DotNet
2.0 - in winforms, but that's not so important). I've got two combo boxes
(combo1 and combo2), both are populating via database calls (using a
separate DB handler class). "combo1" contains a list of countries and is
fairly static, it can be added to but no other external events cause a
change in its population. "combo2" however is populated with a list of
options...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |