根据X算出t

- (void)getValue:(UISlider*)slider{

//float aaa = 200;

volatilefloatx0 =self.redView.center.x;

volatilefloaty0 =self.redView.center.y;

volatilefloatx1 =self.yellowview.center.x;

volatilefloaty1 =self.yellowview.center.y;

volatilefloatx2 =self.blueview.center.x;

volatilefloaty2 =self.blueview.center.y;

volatilefloatx3 =self.orangeView.center.x;

volatilefloaty3 =self.orangeView.center.y;

//NSLog(@"%@", NSStringFromCGPoint([ self pointOnCubicBezierWithControlPoints:x1 :y1 :x2 :y2 :slider.value]));

volatilefloatdx, cx, bx, ax;

staticfloatxt;

xt = slider.value;

//self.ylabel.center = CGPointMake(self.slider.value, 100);

cx =3* (x1 - x0);

bx =3* (x2 - x1) - cx;

ax = x3 - x0 - cx - bx;

dx = x0 - xt;

volatilefloatcy, by, ay, yt;

cy =3* (y1 - y0);

by =3* (y2 - y1) - cy;

ay = y3 - y0 - cy - by;

//yt =

//NSLog(@"cx= %f bx = %f ax = %f cy = %f by = %f ay = %f", cx, bx, ax, cy, by, ay);

volatilefloatm1 , m2, m3, delt;

volatilefloatA , B, C, Y1, Y2, K, T;

//K = sqrtf(2);

A = bx * bx -3* ax * cx;

B = bx * cx -9* ax * dx;

C = cx * cx -3* bx * dx;

delt = B * B -4* A * C;

K = B / A;

T = (2* A * bx -3* ax * B) / (2* A *powf(A,0.5));

Y1 = A * bx +3* ax * ((-B +powf(delt,0.5))/2);

Y2 = A * bx +3* ax * ((-B -powf(delt,0.5))/2);

NSLog(@"Y1 = %f, Y2 = %f", Y1, Y2);

if(A ==0&& B ==0) {

m1 = m2 = m3 = (-cx) / bx;

}elseif(delt >0){

//

floatf1, f2;

if(Y1 <0) {

f1 = -pow(fabsf(Y1),1.0/3);

}else{

f1 =pow(Y1,1.0/3);

}

if(Y2 <0) {

f2 = -pow(fabsf(Y2),1.0/3);

}else{

f2 =pow(Y2,1.0/3);

}

m1 =(-bx - (f1 + f2)) / (3* ax);

NSLog(@"%f", Y2);

}elseif(delt ==0){

m1 = (-bx / ax) + K;

m2 = m3 = -K /2;

}else{

m1 = (-B -2*powf(A,0.5) *cosf(acosf(T) /3)) / (3* ax);

m2 = (-B +powf(A,0.5) * (cosf(acosf(T) /3) +powf(3,0.5) * (sinf(acosf(T) /3)))) / ((2* A) *powf(A,0.5));

m3 = (-B +pow(A,0.5) * (cosf(acosf(T) /3) -powf(3,0.5) * (sinf(acosf(T) /3)))) / ((2* A) *powf(A,0.5));

}

NSLog(@"delt =%f,xt = %f , t = %f",delt,slider.value,m1);

yt = ay *pow(m1,3) + by *pow(m1,2) + cy * m1 + y0;

//xt = ax * pow(m1, 3) + bx * pow(m1, 2) + cx * m1 + x0;

CGPointcenter = [selfpointOnCubicBezierWithControlPoints:x1 :y1 :x2 :y2 :m1];

[self.labelremoveFromSuperview];

self.label= [[UILabelalloc]initWithFrame:CGRectMake(0,0,30,30)];

self.label.center=CGPointMake(center.x, center.y);

self.ylabel.center=self.label.center;

//NSLog(@"sliderValue == %f xt = %f, yt = %f, t = %f", aaa, xt, yt, m1);

//NSLog(@"%f=%f", self.label.center.x, self.label.center.y);

self.label.backgroundColor= [UIColorbrownColor];

[selfaddSubview:self.label];

}

你可能感兴趣的:(根据X算出t)