Tuesday, July 28, 2009

Can anyone suggest a solution for this problem?

I need to design a program that interfaces with another program. The basic gist of my program is that it needs to receive the X,Y %26amp; Z coordinates of various points and determine whether or not the points form a Quorum. A quorum is 3 points or more such that each point is less than 30m away from 2 other points.


The program is not aware of how the coordinates will be entered (so cannot be limited to integers or doubles or whatever) and cannot presume that there's an expected number of coordinates that will be received (so one coordinate can be received or 200).


Please bear in mind that this will be implemented in Java or C#

Can anyone suggest a solution for this problem?
Well first of all you will have to know something about how they will be entered and since you are talking points, they will have to be numbers or strings representing numbers. Secondly, you must always know which is the x, y and the z coordinate so there either has to be a test that numbers must pass or you must always specify the specific order.





Now, the way I would tackle this is using an array of points. Since you must have at least 3 to form a quorum, you can automatically have it return that it is not a quorum if you have less than 3 points.





Next, once you have all the points entered or one at a time, you can have it check if it is a quorum. You will need to use a pythagorean theorem that checks the distance between one point and another point on each plane. So I would make sure you create a generic Pythagorean theorem function which returns an integer (distance m between two points).





So for instance you have the following points (in x, y, z order)...





1,2,3 and point 1,10,3 and point 1,10,8





1) We have three points so it could potentially be a quorum


2) Point 1 and point 2 are only 8 units away on the y axis (10 minus 2) so far so good.


3) Point 2 and point 3 are 5 units away on the z axis (8 minus 3)


4) This is where the theorem comes in... between points 1 and 3 (8 squared + 5 squared = distance squared)





64 + 25 = 89 squared or about 9.434 units away.





Since all three points are within 30 units it is a quorum.





Now this example was really simple because the points were simple and small, plus point 2 and point 3 were lined up. But lets say you put point 3 at coordinates 1,8,8 you would have to run the theorem for point 1 to point 3 (going down on the z-axis and over on the y-axis) and then point 2 and 3 (going down on the z-axis as well as over on the y-axis).





It is hard to explain without drawing a picture so I recommend you draw a 3-D cube and plot a few points on paper. Then re-read what I am saying so you can see what I am talking about.





As you can probably tell from this process it gets exponentially large really quick with the more points you add. So make sure your theorem equation is small and fast and try to limit your inputs to probably something under 30 points or so.





So you loop through your points in the array, checking each one against point 1. Then go to point 2 and check points 3 onwards against it. Then point 3 checks point 4 onwards against it. You could use a point class to accomplish this but be careful because that could also add some confusion later.





Hope this made sense to you. Be sure to draw the picture, it will help you tremendously.





Good luck!
Reply:Don't forget that the Pythagorean Theorem works equally well in 3 Dimensions as it does in 2 dimensions.





You want to use this as your distance calculation:


Dist = Sqrt(X*X + Y*Y + Z*Z) Report It

Reply:I assume that the data input comes through a standard in-buffer.





You might want to make a Point class. This class should store the three coordinates. As you do not know what the coordinates are, I would suggest that you use the primitive data type double to store the x, y and z coordinates. double can store integers as well as decimals. If you get you coordinates as expressions or fractions or some other strange input, you need some way to transform the input into a decimal.





The class should also have a method that takes another Point object and determines whether the two objects are within 30 meters of each other.





The controlling program shoul have a storage area for the points. As you do not know the size of the input, a linked list night be be the best solution.





When the entire input is read, you can do a double-nested loop through the linked list and perform your method from the Point class on each pair of Point objects in the list.





The number of points within a 30 meter radius can be stored in an integer array. As you now know the size of the input (you've read it all), you know what size you need on the array.








The rest is program craft.
Reply:Send your paratmeters(XYZ), validate them if they are null, empty etc.





than form your Quorum





If you haven't solved the problem , send me an E-Mail at http://www.skillipedia.com and I will send you the code


and specify whether it is web based or just stand-alone application


Cheers
Reply:You'll need to define the 'how' of getting data from the other app to yours. The simplest approch is XML and this will be valid whether you send the data as a file, through a web service, or through a messaging system. Both ends will know how to read and write XML.





Regarding the data type, you can either define it to be a numerical type, or just use a string format and then you'll have to do your own parsing to check that what's entered really is a number.





In your XML you can define that there can be repeating sets of co-ordinates, and if you choose you can limit it to 200.





With any kind of integration the part that needs to be right and is worth working on first is the interface definition, in other words defining how the data will get from A and B and in what format. Once that's agreed writing your app will be the easy part!


No comments:

Post a Comment