Steve
Steve
Jay Orsaw wrote:A person I am working with wants me to sort from lowest to highest based on our 'Z' coordinate. I.E., if items are stacked behind each other those should be printed first, and then the ones behind it etc. He says that we need to get all of the Z's and place them in sorted order. So if item 1-5 and 8-10 are Z0 then will be placed into the array before 6-7 if they were Z1. They say that we should put them in an array as #'s and sort by the Z until we fill out array of lets say 100 items; however they said that the face #'s will be lost.
So I'm essentially asking is there a way to sort by the Z numbers and sort each face that way, or do I have to do their method of putting it into a string and sorting it by a padded string... I think it's much easier if you could sort a class based on a method/field in the class, but I'm not sure if it's possible... I have an Class called Face, which I made as an array of faces. So if I have a method called Face(i).z can I do an array sort based on z?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Jay Orsaw wrote:A person I am working with wants me to sort from lowest to highest based on our 'Z' coordinate. I.E., if items are stacked behind each other those should be printed first, and then the ones behind it etc. He says that we need to get all of the Z's and place them in sorted order. So if item 1-5 and 8-10 are Z0 then will be placed into the array before 6-7 if they were Z1. They say that we should put them in an array as #'s and sort by the Z until we fill out array of lets say 100 items; however they said that the face #'s will be lost.
So I'm essentially asking is there a way to sort by the Z numbers and sort each face that way, or do I have to do their method of putting it into a string and sorting it by a padded string... I think it's much easier if you could sort a class based on a method/field in the class, but I'm not sure if it's possible... I have an Class called Face, which I made as an array of faces. So if I have a method called Face(i).z can I do an array sort based on z?
Jay,
The basic answer to your question is: Yes. There are collections and classes in Java that allow you to sort things pretty much any way you like, the main ordering class being Comparator (java.util.Comparator).
To be honest, I have no idea what all this "Z" business is about. Perhaps it's part of your class and it makes sense to you, or it's some Physics or Chemical standard that I know nothing about, but you've explained it badly.
Tell us what you're trying to sort (or, I suspect, group), in simple terms, and I think we'll be able to help you better.
Winston
Jay Orsaw wrote:So I'm essentially asking is there a way to sort by the Z numbers and sort each face that way, or do I have to do their method of putting it into a string and sorting it by a padded string...
I think it's much easier if you could sort a class based on a method/field in the class, but I'm not sure if it's possible... I have an Class called Face, which I made as an array of faces. So if I have a method called Face(i).z can I do an array sort based on z?
Sorry, what I meant was the z order, meaning the depth of items, aka if I had one item placed on top of another it would be based on the depth of the item. So lets say item 1 is 3" and item 2(which is in front of item 1) is another 3" which would be a total of 6." These items would be stacked... Lets say item 3 is 1" in it's own place, and item 4 is 5" in it's own spot. The item order would be item 3, 1,4,2. 1",3",5",6"
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Jay Orsaw wrote:So I'm essentially asking is there a way to sort by the Z numbers and sort each face that way, or do I have to do their method of putting it into a string and sorting it by a padded string...
Probably a bad idea. Strings make poor substitutes for numbers.
I think it's much easier if you could sort a class based on a method/field in the class, but I'm not sure if it's possible... I have an Class called Face, which I made as an array of faces. So if I have a method called Face(i).z can I do an array sort based on z?
Yes.
Sorry, what I meant was the z order, meaning the depth of items, aka if I had one item placed on top of another it would be based on the depth of the item. So lets say item 1 is 3" and item 2(which is in front of item 1) is another 3" which would be a total of 6." These items would be stacked... Lets say item 3 is 1" in it's own place, and item 4 is 5" in it's own spot. The item order would be item 3, 1,4,2. 1",3",5",6"
And this is where you lose me. If you sort purely based on the depth, then the order (from what you described above) would be 3, 1, 2, 4 (1", 3", 3", 5"), unless your method has some way of "knowing" that items are stacked. Furthermore, if they are 'stacked', wouldn't you want to treat them as a single item?
Is this some kind of packing algorithm? Because that's what it sounds like.
Winston
Jay Orsaw wrote:1. He basically wanted to use the string with the data, he uses VB6, which is very limited on a lot of things,
Unless there is another way to figure out which item is on top of another, I haven't really thought too much into it/research on it...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Jay Orsaw wrote:1. He basically wanted to use the string with the data, he uses VB6, which is very limited on a lot of things,
Yes, but you're writing this in Java, not in VB; and in Java, Strings that are used instead of a more appropriate type (such as int or Integer) are EVIL.
That doesn't stop you from accepting Strings as input, but convert them to an appropriate type as quickly as possible.
Otherwise you'll end up with a VB program written in "pseudo-Java". Bleccch!.
Unless there is another way to figure out which item is on top of another, I haven't really thought too much into it/research on it...
Then I definitely would. You should probably find out how the current program does it, but it seems like a mighty odd set-up to me. That would suggest that each piece of inventory (or whatever it is) "knows" its own position on a shelf, which would further suggest that it has to be updated each time it's 'moved'.
It's possible that a rudimentary algorithm could be implemented as a Stack (see java.util.Stack) or Deque, where the top item is simply pop()ed off, but again, it seems a bit odd. You might want to think about a Shelf class (if that's in fact what you're trying to model), but it definitely sounds like you need to get more detail about the procedure before you continue.
Winston
A person I am working with wants me to sort from lowest to highest based on our 'Z' coordinate.
Paul Clapham wrote:I've been reading this thread and I have the feeling that something is missing. And that something is, you haven't said what you want to sort. For example you started out by saying
A person I am working with wants me to sort from lowest to highest based on our 'Z' coordinate.
Notice how you didn't say what you wanted to sort?
So let's talk about that. What do you want to sort? Do you have objects of an Item class which have a Z property? Or what?
Paul Clapham wrote:No, that's all completely wrong.
Well, not completely wrong. The part where you create a Comparator is right. But you don't call the comparator yourself, you just pass it to the Arrays.sort() method and let the sorting call the comparator. Why don't you have a look at this tutorial which explains it a lot more professionally than I could?
Jay Orsaw wrote:I have A class called "Face" with multiple properties, one of which is the depth of the object which would be it's Z-Order(Z coordinate). This is used to sort the items when I read them in and put them out onto the screen. Sometimes some are stacked so they need to be stacked in the right way, so we are using the Z-coordinate to do this.
What I am looking for is to be able to sort my array based on the Z, which would be a method, or a field in my Face class. Sometimes things have to stay in the back no matter what, and sometimes items have to stay in the front no matter what. There are lots of things that are weird, so we figured this would be the best solution; having things sorted by their position, so that they will be read and printed out in the order of the array.
I'm not sure what exactly I would compare. I was looking at a tutorial that was comparing strings.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Jay Orsaw wrote:I have A class called "Face" with multiple properties, one of which is the depth of the object which would be it's Z-Order(Z coordinate). This is used to sort the items when I read them in and put them out onto the screen. Sometimes some are stacked so they need to be stacked in the right way, so we are using the Z-coordinate to do this.
Perhaps it's just your terminology, but to me "stacking" is putting things on top of each other (which you actually mentioned above), and that, surely, would be a Y-axis value (if Z is depth).
It also bothers me a bit that the algorithm seems to rely on Items "knowing" their position. Are these items individually identifiable (eg, with a barcode), so that you can find them and update them? It seems we're still missing an awful lot of useful information.
What I am looking for is to be able to sort my array based on the Z, which would be a method, or a field in my Face class. Sometimes things have to stay in the back no matter what, and sometimes items have to stay in the front no matter what. There are lots of things that are weird, so we figured this would be the best solution; having things sorted by their position, so that they will be read and printed out in the order of the array.
Fine, but if it truly is a 3D "position", then 3 coordinates are going to be involved, not just one (and I'm not so sure that your values aren't dimensions, or lengths, rather then coordinates). Java already has a 2D coordinate class called Point (java.awt.Point), which is already mutable; but its implementation is horrible, so I'm not sure I'd advise it. It might give you some pointers to defining your own 3D one though, perhaps with Comparators for length, height and width.
I'm not sure what exactly I would compare. I was looking at a tutorial that was comparing strings.
Well DON'T. Everything you've said so far indicates that those z coordinates are numbers, so make them numbers.
As to the (v1 - v2) business, it's simply a standard method for returning a positive value if v1 > v2, a negative value if v1 < v2, and 0 if they're equal, which is exactly the contract for Comparator.compare(). [Edit] I should perhaps add that it only works when v1 and v2 are both guaranteed to be >= 0 (as with a String length), or <= 0.
But as Paul said, we really need to know a bit more about what these things are and a better description of what you're trying to do. Is this inventory? Is it a shelf stacking algorithm, or for stock picking?
Enquiring minds want to know.
Winston
Jay Orsaw wrote:1. Yeah stacking one in front of the other.
If you look at an actual 3D chart then I would assume it would be the Y(as Z does up and down), but we are looking at it as a front view X,Y and the Z is just the Depth. I'm not too fond of it either, but it seems this is what is needed to do.
Some things need to stay in the back, lets say a sign, and somethings need to stay in front lets say a door.
These items all have UPC, SKU, etc codes, to identify each, but they don't change.
The only position the items need to know is if one is behind or in front of another. I personally didn't think it mattered, but sometimes things have to always stay in back, or in front.
Basically if one item is dragged over another it will ask to be put into a stack
when that happened the one on top will have to be identified as such
Originally the one in back was to always stay in the back, so if you moved it left and right it would stay behind the one, but I personally think that's stupid and people will want to drag items over one another, not have to worry about items staying behind each other.
Sorry if I'm not being more specific, I'm not sure what else I need to add...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:Phew. A lot to answer here:
OK, well might I suggest you come up with another term, particularly if your algorithm has to deal with height (which it sounds like it does) - 'blocking' or 'covering' seem like possibilities.
I guess I'll use dragged over, or over....
Actually, if I was looking at a 3D chart of a stock shelf, I'd expect it to be projected from the front, so z seems perfectly reasonable to me for depth.
yup![]()
??? So you're including everything? To me, a sign would be part of the backboard, wouldn't it? Or is it part of your inventory? It certainly doesn't seem like you'd have much depth to worry about. And you've really lost me with a door, unless this is DIY stuff.
Yup, everything... Some things have to stay in the back, some in the front.. Like a freezer door, you would put the items behind it, and yest it's DIY for the people trying to create it.
Well, thank God for small mercies.
![]()
![]()
And this seems to me an important fact. What are the rules for those?
Like I said signs, doors, etc, they will be handled later.
Again, I suspect, another important action. What do you mean by "dragged over"?
The way we thought to order the Z-Order would be only if one item was dragged over the first item, and it would ask if the items want to be stacked, or else it would put it back it it's original spot. Once you click yes to stack the first item would be the first item behind it, with a Z-Order of lets say 3, and in front of it will be the next item with a Z-order of lets say 5....
And now you're using 'on top', which suggests that this is not simply a "front-to-back" algorithm.
Sorry there is no top, if I say that I mean front.
Sorry, you've totally lost me here.
Nvm this part it has nothing to do with anything anymore.
Sorry if I'm not being more specific, I'm not sure what else I need to add...
I think you need to describe what it is you're trying to do. Right now, all we have is a bunch of terminology that is difficult to follow to an implementation that we (or at least I) don't understand.
Most packing algorithms assume:
(a) Some uniformity in the things you're trying to pack.
(b) Some method of selection (eg, "topmost; furthest forward").
(c) Some sort of "box" that fits around the items being stocked (a bit like the 'rectangle' that fits around a GUI item, but in 3D). If you know that, you can find the "centre", which makes working out (b) a lot easier.
But from what you've described so far, your "items" include all sorts of things like signs and doors.
Simple explanation please. And explain the process, NOT the implementation. Some idea of what these items are would also be useful. I've spent more than 15 years on inventory systems, so I suspect I could help; but your explanation isn't helping. Once again: back up, and explain the basic process.
Winston
Jay Orsaw wrote:Idk why, but I guess my explanation still makes no sense.... What would you do if you had 2 items 1 behind the other? How would you identify them? Make sure that you're grabbing the front most item?
Maybe i will print out a picture...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Jay Orsaw wrote:Idk why, but I guess my explanation still makes no sense.... What would you do if you had 2 items 1 behind the other? How would you identify them? Make sure that you're grabbing the front most item?
As I said above, I'd probably implement it as a Stack or LIFO queue of some kind, push()ing Items in and pop()ing them out; although a linked list might work just as well. The nice thing about that is that Items don't need to know anything about "where" they are; it's inherent in their position in the Stack.
The problem seems to be in all the other rules you have, which I'm still not clear about, like Items being 'above' others and this 'crossing over' business.
Maybe i will print out a picture...
That might be a very good idea.
Winston
Jay Orsaw wrote:Well I still have to sort it, so how would I sort it based on a variable? I'm trying to find tutorials online to sorting classes and their elements using the Java.util.Arrays, but nothing really so far...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Jay Orsaw wrote:For all of those who said my "Z-Order" didn't make any sense, or w/e other stuff, guess what I found...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Winston Gutkowski wrote:
Jay Orsaw wrote:For all of those who said my "Z-Order" didn't make any sense, or w/e other stuff, guess what I found...
And neither of those things have anything to do with what most of us (certainly me) assumed you meant. Why didn't you just tell us that this was a visual pane stacker in your first post?
Winston
Jay Orsaw wrote:My q was clear, so was the answer, which was 100% was I asked.... I said they stacked, 1000 times. Yo wanted me to tell yo everything I was doing which didn't have any inpt or help at all. I even showed code I was sing to get help.....
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|