# iPhone 6 Plus 上的 GLSL atan 给出错误结果GLSL atan on iPhone 6 Plus gives wrong result

``````void main()
{
highp float y = 0.57;
highp float x = 0.21;

highp float a = atan(y, x);
// works if changed to atan(0.57, 0.21);
// does not work if changed to atan(y / x);

if (a > 1.2 && a < 1.25)
{
// Should always come here
// Works on Simulator, iPhone 5
gl_FragColor = vec4(1, 0, 0, 1);
}
else if (a > 1.5 && a < 1.55)
{
// Comes here on iPhone 6 Plus
gl_FragColor = vec4(0, 1, 0, 1);
}

return;
}
``````

``````highp float y = texCoord.x;
highp float x = texCoord.x;

if (x == x) // Removing this line makes error return
{
x = 0.21;
}

if (y == y) // Removing this line makes error return
{
y = 0.57;
}
``````

``````float y = sin(lon2 - lon1) * cos(lat2);
float x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon2 - lon1);

float bearing = atan(y, x) + 2.0 * pi;

return mod(bearing, 2.0 * pi);
``````

``````float y = texCoord.y;
float x = texCoord.x;

if (y == y)
{
y = sin(lon2 - lon1) * cos(lat2);
}

if (x == x)
{
x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon2 - lon1);
}

float bearing = atan(y, x) + 2.0 * pi;

return mod(bearing, 2.0 * pi);
``````

## 2 个回复2

### #2楼 票数：0

``````float getAngle(vec2 point, vec2 center) {
float y = point.y - center.y;
float x = point.x - center.x;
return atan(y, x);
}
``````

``````vec2 p1 = vec2(40.0, 30.0);
vec2 p2 = vec2(40.0, 30.0);
float angle = getAngle(p1, p2);
``````

``````float getAngle(vec2 point, vec2 center) {
float y = point.y - center.y;
float x = point.x + 0.000000001 - center.x;
return atan(y, x);
}
``````

2回复

1回复

1回复

1回复

1回复

1回复

2回复

3回复