iphone toRadians toDegrees compiler problem

2019-07-29 11:23发布

I am trying to convert a double to radians using the Objective c function toRadians like this:

double oldLat = toRadians(oldLocation.coordinate.latitude);

but I keep getting a compiler warning and error or implicit declaration of toRadians and toDegrees

I included #import <math.h> but that didn't solve the problem for some reason.

any help would be greatly appreciated.

2条回答
该账号已被封号
2楼-- · 2019-07-29 12:17

There is no toRadians in the Foundation classes. You can just convert it manually

degrees * M_PI / 180.0

Foundation imports math.h so you'll have M_PI otherwise you'll have to

#include <math.h>

查看更多
三岁会撩人
3楼-- · 2019-07-29 12:27

try this coding:- ( radian to degree)

location = [[CCDirector sharedDirector] convertToGL:location];

        // Determine offset of location to projectile
        int offX = location.x - PROJECTILE_POSITION_X;
        int offY = location.y - PROJECTILE_POSITION_Y;

                int realX = winSize.width + (PROJECTILE_WIDTH/2);
        float ratio = (float) offY / (float) offX;
        int realY = (realX * ratio) + PROJECTILE_POSITION_Y;

        int offRealX = realX - PROJECTILE_POSITION_X;
        int offRealY = realY - PROJECTILE_POSITION_Y;

        // Determine angle to face
        float angleRadians = atanf((float)offRealY / (float)offRealX);
        float angleDegrees =  (__angleRadians__)/((__angleRadians__) * 57.29577951f);
查看更多
登录 后发表回答