• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Pixels to Feet Calculation

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 28333
97
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Paul Clapham
Sheriff
Posts: 28333
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way you can apply the same dimensional analysis to your pixels: if you have pixel/foot and you want pixel/sec, then pixel/foot times foot/sec gives you pixel/sec.
 
Paul Clapham
Sheriff
Posts: 28333
97
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:


 
Casey Clayton
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the help guys finally got it working properly!

 
Squanch that. And squanch this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic