cair71
cair71

Reputation: 23

Need good calculation to get right index by x from width

enter image description here

Here, I made a canvas app with total width is (742px), so here what I need, I just want to calculate and get right section (Index) by X only.

Example, I got 393.9015504531791 as X calculated with whole width, So X here it's 0.5x in real, how do I would calculate that and get right Index between (1-17) only through X? enter image description here

I tried many calcs I know, but honestly I'm not good on Math lol.

Upvotes: 0

Views: 48

Answers (1)

MBo
MBo

Reputation: 80325

OneWidth = 542 / 17
LeftEdge = (742 - 542) / 2
Index = Math.floor((X - LeftEdge) / OneWidth) + 1

Upvotes: 0

Related Questions