gpt4 book ai didi

ios - 从 X 米的单一位置坐标创建垂直经纬度

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:01:26 26 4
gpt4 key购买 nike

我有用户当前位置,即 CLLocation 坐标(位置纬度和经度)并且用户在用户当前位置的帮助下指向一个方向我现在创建了一个区域我想要更多的赛道坐标(比如 2m ,垂直方向距跑道4m、6m),跑道长10m。请检查图像,红点在轨道上。 Please check this image

最佳答案

/**
* Returns the destination point from initial point having travelled the given distance on the
* given initial bearing (bearing normally varies around path followed).
*
* @param {double} distance - Distance travelled, in same units as earth radius (default: metres).
* @param {double} bearing - Initial bearing in degrees from north.
*
* @returns {CLLocationCoordinate} Destination point.
*/

#define kEarthRadius 6378137

- (CLLocationCoordinate2D)destinationPointWithStartingPoint:(MKMapPoint)initialPoint distance:(double)distance andBearing:(double)bearing {
CLLocationCoordinate2D location = MKCoordinateForMapPoint(initialPoint);

double delta = distance / kEarthRadius;
double omega = [self degreesToRadians:bearing];

double phi1 = [self degreesToRadians:location.latitude];
double lambda1 = [self degreesToRadians:location.longitude];

double phi2 = asin(sin(phi1)*cos(delta) + cos(phi1) * sin(delta) * cos(omega));
double x = cos(delta) - sin(phi1) * sin(phi2);
double y = sin(omega) * sin(delta) * cos(phi1);
double lambda2 = lambda1 + atan2(y, x);

return CLLocationCoordinate2DMake([self radiansToDegrees:phi2], ([self radiansToDegrees:lambda2]+540)%360-180);
}

- (CLLocationCoordinate2D)rhumbDestinationPointForInitialPoint:(MKMapPoint)initialPoint distance:(double)distance andBearing:(double)bearing {
CLLocationCoordinate2D location = MKCoordinateForMapPoint(initialPoint);

double delta = distance / kEarthRadius;
double omega = [self degreesToRadians:bearing];

double phi1 = [self degreesToRadians:location.latitude];
double lambda1 = [self degreesToRadians:location.longitude];

double delta_phi = delta * cos(omega);
double phi2 = phi1 + delta_phi;

// check for some daft bugger going past the pole, normalise latitude if so
if (fabs(phi2) > M_PI / 2) {
phi2 = phi2 > 0 ? M_PI-phi2 : -M_PI-phi2;
}

double delta_gamma = log(tan(phi2/2+M_PI/4)/tan(phi1/2+M_PI/4));
double q = fabs(delta_gamma) > 10e-12 ? delta_phi / delta_gamma : cos(phi1);

double delta_lambda = delta*sin(omega)/q;
double lambda2 = lambda1 + delta_lambda;

return CLLocationCoordinate2DMake([self radiansToDegrees:phi2], ([self radiansToDegrees:lambda2]+540)%360-180);
}

- (double)degreesToRadians:(double)degrees {
return degrees * M_PI / 180.0;
}

- (double)radiansToDegrees:(double)radians {
return radians * 180.0 / M_PI;
}

改编自:http://www.movable-type.co.uk/scripts/latlong.html
有关轴承的更多信息:https://en.wikipedia.org/wiki/Bearing_(navigation)
和恒线:https://en.wikipedia.org/wiki/Rhumb_line

关于ios - 从 X 米的单一位置坐标创建垂直经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36402540/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com