473,396 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Nearest 2d coordinates

Hi,

Can anyone help me to write code for finding nearest coordinates from aset of coordinates.
Mar 11 '08 #1
4 1855
MACKTEK
40
Lets do this using the Socratic method.

First, do you know whether or not you are supposed to use cartesian coordinates? or polar coordinates or some other type?
Mar 11 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
Please read the posting guidelines.


I can help with specific programming and design issues but I cannot provide complete solutions or act as a tutor.
Mar 11 '08 #3
whodgson
542 512MB
I'm not sure if you`ve lost interest but what about this for a start:
Supposing you had 2 arrays int x[100] and int y [100] which held your sets of x and y coordinates. And suppose that int variables m and n were the 2 coordinates for which you wanted the closest match from x[i] and y[i].
You could compare the abs value of m with each element in x[ ] using a for loop
like for(int i =0;i<100;i++)
{ min=abs(m-x[i];
if(x[i]<min)min=x[i];} //if x[i]>min it would be ignored
min now holds the least difference between m and x[i] between i=0 and i=99.
If you traversed the x array again you could identify the element which held the value = m+ or - min and its i th position in the array. Repeat for y [] array and variable n.
If you could turn this dog`s breakfast into something vaguely representing an algorithm perhaps the code would follow.
Mar 13 '08 #4
whodgson
542 512MB
Using 'abs' in the above is not required and prevents you from calculating the desired value of x[i] by simply adding min to m. This then avoids the need for a second traverse of the array.
Mar 14 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Suresh Kumar | last post by:
Hi, In Tkinter, how to convert canvas coordinates to window coordinates? To convert window coordinates to canvas coordinates we are using "canvasx,canvasy". But how to do vice-versa? Iam using a...
14
by: John Hunter | last post by:
I have a list of two tuples containing x and y coord (x0, y0) (x1, y1) ... (xn, yn) Given a new point x,y, I would like to find the point in the list closest to x,y. I have to do this a...
2
by: nkunapa | last post by:
Hi: Is there a way in XPATH to find the nearest node of the node in context with a certain attribute value. Here is my problem. I have the following XML and I am trying to add all the nodes with...
4
by: Travis Stewart | last post by:
Hi, I am not very familiar with C++ so the problems I am having might be simple and I just cannot see them or I am totally unaware of why something would be incorrect. Anyway, I'm using the ANN...
16
by: Niels Jensen | last post by:
I have been developing a little project which draw's a hexgrid on a panel within a form similar to this - it:s used as a client from a e-mail based strategy game: ____ ____ / \...
3
by: steve | last post by:
Hi All I have textboxes within a TableLayoutpanel and I want to be able to position an independant control adjacent to a selected textbox This independent control allows selection of text to...
1
by: Cainnech | last post by:
Hi all, I've got a bit of a challenge. I've got a script which displays the mouse coodinates if you click on an image. Now I would like to convert these coordinates to pixelnumber. Let me see if I...
0
by: raylopez99 | last post by:
keywords: logical coordinates, page coordinates, world coordinates, device coordinates, physical coordinates, screen coordinates, client coordinates. offset rectangle. WYSIWYG rubber rectangle...
0
by: mingke | last post by:
Hi.... I'm having difficulties with my codes to list coordinates (in my example codes is 4x4 pixel). I tried two different codes and the results are different.Basically, I tried to declare the sub...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.