0

i have a curve slider that takes in value from the height of the frame which value from -100 to 300 which i need to calculate it to equal the value of 0 to 10.

how can i calculate the negative value as what i had gotten was negative value?

my math is bad :(

     -(NSUInteger)calculatePoints:(float)pointY
{
    NSLog(@"maxOffsetValue %f minOffsetValue %fand pointY %f",maxOffsetValue,minOffsetValue, pointY);

    float value =  maxOffsetValue + minOffsetValue;
    NSLog(@"value %f",value);
    float normalValue = (pointY * 1.5) / value ;
    NSLog(@"normalValue %f",normalValue);

    return normalValue;
}
//set value from point
-(void) setValueFromPoint:(CGPoint) point
{
    [animationTimer invalidate]; 

    NSInteger value = [self calculatePoints:point.y];
    value = ((value / self.frame.size.height) * self.max);

    NSLog(@"raw value %d",value);
    value < 0 ? value = 0 : value;
    value > self.max ? value = self.max : value;
    self->_value = value;
    NSLog(@"Value %d",value);
}
Desmond
  • 4,943
  • 14
  • 51
  • 112

2 Answers2

1

You can get your value scaled between 0 and 10 by using

(x + 100) / 40

where x is the value between -100 and 300.


Reference

Community
  • 1
  • 1
aksh1t
  • 5,330
  • 1
  • 32
  • 53
1

Just a short answer.

((point.y-(-100))/400) * 10

KudoCC
  • 6,722
  • 1
  • 21
  • 48