I have a large box say the BIG COMPARTMENT, this compartment is divided horizontally into multiple compartments of equal units.
Details: 1.The BIG compartment has its leftmost end on negative x axis and rightmost end on positive x axis so in between there are negative transforms.
What we have: 1. Number of compartments 2.starting X position of Big compartment 3.Ending X position of Big compartment 4.x position of an object placed on that BIG compartment
What we want: The nth number of compartment on which the object is based on the position of object.
Problem: Can not derive a formula that can handle position of object while on negative x to calculate the nth compartment .
What I guessed:
(width of compartment - position of object)/number of compartment
But this does not work at all with negatives
Let x_start
, x_end
, x_obj
and n
denote starting X coordinate, ending X coordinate, X coordinate of object, and number of compartment repectively.
Then the compartment in which object falls = [(x_obj - x_start)/(x_end - x_start)] * n
This assumes that if x_starts
falls on the shared edge of 2 compartments, than it goes into the left compartment
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments