简体   繁体   中英

Functions in objective-c IOS

I have an equation:

CGPoint point1 = CGPointMake(20, 100);
CGPoint point2 = CGPointMake(300, 100);
CGPoint controlPoint1 = CGPointMake(50, 250);
CGPoint controlPoint2 = CGPointMake(100, 250);

B(t) = (1-t)^3 * point1 + 3 * (1-t)^2 * t controlPoint1 + 3 * (1-t) * t^2 * controlPoint2 + t^3 * point2;

And I am trying to run it using an NStimer to get different values for B(t). I set 't' to be an integer (int t in my .h file). The problem is that I get the error:

"Implicit declaration of function B is invalid in C99"

If I do:

int h = (1-t)^3 * point1 + 3 * (1-t)^2 * t controlPoint1 + 3 * (1-t) * t^2 * controlPoint2 + t^3 * point2;

I get:

"Invalid operants to binary expression (int and CGPoint)".

and a pointer to the multiplication sign (*)

The first error is because B(t) looks like a function to the compiler, not a function in the mathematical sense. Storing the value in a variable like you've done will work, or you could write a function which accepts t and returns the current value.

The second error is because you are multiplying a scalar value (int) by a struct (CGPoint), you need to be multiplying by one of the points values (CGPoint consists of an x and y value), eg change point1 to point1.x (disclaimer, i don't know this function so you'll have to work out which should be used)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM