posted 3 years ago

I have a piece of software that I have been working on that takes some information about boxes on a conveyor from a database and then needs to do an animation based on that information to show the boxes moving across the conveyor. The problem I am having is figuring out the proper algorithm to calculate the duration of the animation for each box. So what I have is a track, which has a set length in feet and a set speed which is feet per second. Now the actual shape I am using for the track in javafx is 1200px. Now I need to take say a track length of 21 feet with a speed of 1ft/s and figure out how long the animation should last, for testing each box is being thrown on the conveyor in random positions and the track length could change between tracks.

So for example if we have a conveyor that is 21 feet with a speed of 1ft/s and the boxes current position is 10 feet in then we calculate how long it will take for the animation to complete for that specific box, the trouble comes in when converting things from pixels to feet since the physical track object in the program will always be equal to 1200px no matter what the actual size of the track is..so a 21 foot track will be displayed as a 1200px rectangle but a 500 foot track would also be a 1200px rectangle.

Hopefully I made it clear enough if not I can try to elaborate more if needed.

So for example if we have a conveyor that is 21 feet with a speed of 1ft/s and the boxes current position is 10 feet in then we calculate how long it will take for the animation to complete for that specific box, the trouble comes in when converting things from pixels to feet since the physical track object in the program will always be equal to 1200px no matter what the actual size of the track is..so a 21 foot track will be displayed as a 1200px rectangle but a 500 foot track would also be a 1200px rectangle.

Hopefully I made it clear enough if not I can try to elaborate more if needed.

posted 3 years ago

You want an answer in seconds, so you're going to have to multiply feet by seconds/feet (yes, the dimensions work just like their values do in arithmetic). So suppose your track length is 18 feet and the speed is 2 feet/second. To get seconds/feet you take the reciprocal, so that's 0.5 seconds/feet. Multiplying that by 18 feet gives you 9 seconds for the length of the animation.

Now, that's assuming you want your animation to take the same amount of time that the box actually takes to move along the conveyor. You might want to speed it up, because having it take 9 seconds to cross a small computer monitor might not produce the right effect. However I'd leave that part aside for now and just work on simulating the box's travel in real time. Inserting a speed-up (or slow-down) factor could be done later without too much difficulty.

- 1

Casey Clayton wrote:So what I have is a track, which has a set length in feet and a set speed which is feet per second... Now I need to take say a track length of 21 feet with a speed of 1ft/s and figure out how long the animation should last...

You want an answer in seconds, so you're going to have to multiply feet by seconds/feet (yes, the dimensions work just like their values do in arithmetic). So suppose your track length is 18 feet and the speed is 2 feet/second. To get seconds/feet you take the reciprocal, so that's 0.5 seconds/feet. Multiplying that by 18 feet gives you 9 seconds for the length of the animation.

Now, that's assuming you want your animation to take the same amount of time that the box actually takes to move along the conveyor. You might want to speed it up, because having it take 9 seconds to cross a small computer monitor might not produce the right effect. However I'd leave that part aside for now and just work on simulating the box's travel in real time. Inserting a speed-up (or slow-down) factor could be done later without too much difficulty.

Casey Clayton

Ranch Hand

Posts: 41

posted 3 years ago

See I have that basic calculation down but the problem occurs when the placing the boxes and then doing the calculation. I receive the boxes last known location in feet, which I need to convert to pixels to place it properly on the screen. This is the calculation I am having trouble with I guess, taking that data in feet and converting it to pixels since that the track will always be 1200px on the screen but the actual length in feet will vary from track to track. So say if it is a 40 foot track and the box is 12.5 feet in then how many pixels do I place box at on the X Axis.

Paul Clapham wrote:Casey Clayton wrote:So what I have is a track, which has a set length in feet and a set speed which is feet per second... Now I need to take say a track length of 21 feet with a speed of 1ft/s and figure out how long the animation should last...

You want an answer in seconds, so you're going to have to multiply feet by seconds/feet (yes, the dimensions work just like their values do in arithmetic). So suppose your track length is 18 feet and the speed is 2 feet/second. To get seconds/feet you take the reciprocal, so that's 0.5 seconds/feet. Multiplying that by 18 feet gives you 9 seconds for the length of the animation.

Now, that's assuming you want your animation to take the same amount of time that the box actually takes to move along the conveyor. You might want to speed it up, because having it take 9 seconds to cross a small computer monitor might not produce the right effect. However I'd leave that part aside for now and just work on simulating the box's travel in real time. Inserting a speed-up (or slow-down) factor could be done later without too much difficulty.

See I have that basic calculation down but the problem occurs when the placing the boxes and then doing the calculation. I receive the boxes last known location in feet, which I need to convert to pixels to place it properly on the screen. This is the calculation I am having trouble with I guess, taking that data in feet and converting it to pixels since that the track will always be 1200px on the screen but the actual length in feet will vary from track to track. So say if it is a 40 foot track and the box is 12.5 feet in then how many pixels do I place box at on the X Axis.

posted 3 years ago

So you know that 40 feet corresponds to 1200 pixels. Therefore you have 1200/40 (= 30) pixel/foot. If you want to know how many pixels correspond to 12.5 feet, then: 30 pixels/foot x 12.5 feet = 375 pixels.

- 1

Casey Clayton wrote:...since that the track will always be 1200px on the screen but the actual length in feet will vary from track to track. So say if it is a 40 foot track and the box is 12.5 feet in then how many pixels do I place box at on the X Axis.

So you know that 40 feet corresponds to 1200 pixels. Therefore you have 1200/40 (= 30) pixel/foot. If you want to know how many pixels correspond to 12.5 feet, then: 30 pixels/foot x 12.5 feet = 375 pixels.

posted 3 years ago

This is a simple mathematical proportion:

you want to solve for pixels down the image, so multiply both sides by total number of pixels. They cancel on the right side, and leave you with

so in your example above

When your box reaches 20 feet:

- 1

Casey Clayton wrote:See I have that basic calculation down but the problem occurs when the placing the boxes and then doing the calculation. I receive the boxes last known location in feet, which I need to convert to pixels to place it properly on the screen. This is the calculation I am having trouble with I guess, taking that data in feet and converting it to pixels since that the track will always be 1200px on the screen but the actual length in feet will vary from track to track. So say if it is a 40 foot track and the box is 12.5 feet in then how many pixels do I place box at on the X Axis.

This is a simple mathematical proportion:

you want to solve for pixels down the image, so multiply both sides by total number of pixels. They cancel on the right side, and leave you with

so in your example above

When your box reaches 20 feet:

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Consider Paul's rocket mass heater. |