CLLocation `distanceFromLocation:` takes into account ellipsoid shape of the Earth - cllocation

I can't seem to see it in the Docs description, but does anyone know if the above method takes into account the ellipsoid shape of Earth or is it based on a spherical shape?
I assume it does, I just need to know for sure!
Thanks in advance.

Yes, it seems like CLLocation.distance(from:) does use some kind of ellipsoid earth model.
Using this Swift code
func testRadius(lat1: CLLocationDegrees, lon1: CLLocationDegrees, lat2: CLLocationDegrees, lon2: CLLocationDegrees, angularDistance: CLLocationDegrees) {
let loc1 = CLLocation(latitude: lat1, longitude: lon1)
let loc2 = CLLocation(latitude: lat2, longitude: lon2)
let angularDistanceRadians = angularDistance * .pi / 180
let meterDistance = loc2.distance(from: loc1)
let earthRadius = meterDistance / angularDistanceRadians // assumes circle!
func coordAsString(_ loc: CLLocation) -> String {
"(\(loc.coordinate.latitude), \(loc.coordinate.longitude))"
}
print(earthRadius, coordAsString(loc1), coordAsString(loc2))
}
// Meridians at longitudes 0°, 90°, 180° and -90°. Poles aren't well-behaved, thus ±89° instead of ±90°
testRadius(lat1: -89, lon1: 0, lat2: 89, lon2: 0, angularDistance: 178)
testRadius(lat1: -89, lon1: 90, lat2: 89, lon2: 90, angularDistance: 178)
testRadius(lat1: -89, lon1: 180, lat2: 89, lon2: 180, angularDistance: 178)
testRadius(lat1: -89, lon1: -90, lat2: 89, lon2: -90, angularDistance: 178)
// Equator from longitudes 0° to 180° and from 90° to -90°
testRadius(lat1: 0, lon1: 0, lat2: 0, lon2: 180, angularDistance: 180)
testRadius(lat1: 0, lon1: 90, lat2: 0, lon2: -90, angularDistance: 180)
you can test the earth's radius along some meridians and the equator. This leads:
6367088.045696135 (-89.0, 0.0) (89.0, 0.0)
6367088.045696135 (-89.0, 90.0) (89.0, 90.0)
6367088.045696135 (-89.0, 180.0) (89.0, 180.0)
6367088.045696135 (-89.0, -90.0) (89.0, -90.0)
6378137.000000001 (0.0, 0.0) (0.0, 180.0)
6378137.000000001 (0.0, 90.0) (0.0, -90.0)
so an equatorial radius of 6,378,137 m and — as we are using pi and radians here instead of the "circumference factor" specific to the ellipse's eccentricity (which we don't know) — a "mean longitudinal" radius of around 6,367,088 m.
These match the commonly used reference ellipsoid WGS-84 also used in GPS, which makes sense as CoreLocation is the API for accessing the iPhone's GPS data.

Did you read the reference?
This method measures the distance between the two locations by tracing
a line between them that follows the curvature of the Earth. The
resulting arc is a smooth curve and does not take into account
specific altitude changes between the two locations.

Related

Transparency in plotted surfaces

I'm using Octave 7.2.0-1 on linux.
When plotting surfaces which overlap (both with facealpha<1) Octave only shows the axes as a "see-through", not the surface which is "behind":
[ xs, ys, zs ] = sphere( 20 );
surf( xs, ys, zs, 'facealpha', 0.5, 'edgealpha', 0.5, 'facecolor', 'r' );
hold on
surf( xs+1, ys+1, zs , 'facealpha',0.5, 'edgealpha', 0.5, 'facecolor', 'g');
Is this a bug?

How to define a piecewise map in sage

I want to define in Sage the following
map. I've attempted to use the following code in Sage:
gamma=function('gamma')
gamma(t)=piecewise([(t>0,(t,0,e^(-1/t^2))),(t==0,(0,0,0)),(t<0,(t,e^(-1/t^2),0))])
This, however, gives me the error TypeError: unable to convert (t, 0, e^(-1/t^2)) to a symbolic expression. How could I change it to create such a type of map?
It seems piecewise does not support vector-valued functions.
Possible workaround: define each coordinate as a piecewise function.
sage: gamma(t) = (t,
....: piecewise([(t <= 0, 0), (t > 0, exp(-t^-2))]),
....: piecewise([(t < 0, exp(-t^-2)), (t > 0, 0)]))
....:
sage: gamma
t |--> (t,
piecewise(t|-->0 on (-oo, 0], t|-->e^(-1/t^2) on (0, +oo); t),
piecewise(t|-->e^(-1/t^2) on (-oo, 0), t|-->0 on (0, +oo); t))
sage: parametric_plot(gamma, (t, -1, 1))
Launched html viewer for Graphics3d Object

plotting multiple graphs on the same figure in Octave

I'm trying to plot multiple graphs on a single figure in Octave. Here is my code: these graphs represents the decrease of the cost function on each iteration of gradient decent:
% Init Theta and Run Gradient Descent
theta = zeros(3, 1);
[theta, J_history] = gradientDescentMulti(X, y, zeros(3, 1), alpha, num_iters);
[theta1,J1]=gradientDescentMulti(X, y, zeros(3, 1), 0.05, num_iters);
[theta3,J3]=gradientDescentMulti(X, y, zeros(3, 1), 0.03, num_iters);
% Plot the convergence graph
figure;
plot(1:numel(J_history), J_history, 'g', 'LineWidth', 2);
hold on;
plot(1:50, J2, 'r');
plot(1:50, J3, 'b');
xlabel('Number of iterations');
ylabel('Cost J');
However, when I run the codes, I got only one graph on the figure without even the labels, The best I was able to d was to put two graph on the same figure:
Is there something wrong with my codes?

Creating a 2 line graph on left axis and a bar graph on right axis Octave

I'm having difficulty creating a 2 y axis graph in Octave. Currently I can make the 2 line graph. However, I haven't been able to find a function that will help me with my problem. I have tried using the plotyy function but I am not sure if you can use this function with two left side axis line graphs and one right side graph. Here is code I have written so far in my attempt.
labels = ["Data 1"; "Data 2"; "Data 3"; "Data 4"; "Data 5"]
y1 = [137, 15, 2, 3, 37]
y2 = [43, 1, 67, 97, 41]
x = [1, 2, 3, 4, 5]
y3 = [0, .2, .3, .104, .09]
z1 = plot(x, y1, y2)
plot(x, y1, y2)
hold on
plot(x, y2)
xlabel("Version")
yyaxis left
ylabel("Y axis")
set(gca,'XTickLabel',labels)
yyaxis right
z = bar(x,y3)
z
yyaxis right
ylabel("Data")
While plotyy is the command to plot two normal plots using distinct left and right yaxes, I don't think you can do what you were trying to do with it. (i.e. mix two plots with a bar chart). However, what plotyy does is literally a simple case of overlaying two axes at the same position and making one 'see-through'. So you can use the same approach in general.
Here's your example above re-worked to achieve this (plus some extra bling):
x = [1, 2, 3, 4, 5]; labels = ["Data 1"; "Data 2"; "Data 3"; "Data 4"; "Data 5"];
y1 = [137, 15, 2, 3, 37]; y2 = [43, 1, 67, 97, 41]; y3 = [0, .2, .3, .104, .09];
ax_left = axes('position', [0.15, 0.12, 0.7, 0.82]); % manually positioned
plot (x, y1, 'r-', 'linewidth', 3); hold on
plot (x, y2, 'g:', 'linewidth', 3); hold off
set (ax_left, ...
'fontsize', 16, 'fontweight', 'bold', 'labelfontsizemultiplier', 1.2, ...
'color', 'none', ... % makes 'background' see-through
'box', 'off', ... % prevents left axis ticks in the right axis
'xlim', [0, 6], 'ylim', [0, 150], 'xtick', x, 'xticklabel', labels);
xlabel('Version'); ylabel('Left Y-Axis');
ax_right = axes('position', [0.15, 0.12, 0.7, 0.82]); % same position as above
bar (x, y3, 0.5, 'facecolor', [0, 0.5, 1]); % nice narrow light blue columns
set (ax_right, ...
'fontsize', 16, 'fontweight', 'bold', 'labelfontsizemultiplier', 1.2, ...
'yaxislocation', 'right', ...
'ycolor', [0, 0.5, 1], ... % same nice light blue color as bar chart
'box', 'off', 'xlim', [0, 6], 'ylim', [0, 0.35], 'xtick', []);
ylabel('Data');
% ensure axes are stacked in the order you want them to appear (bottom to top)
axes(ax_right);
axes(ax_left);

How use Immediate number in AGAL

For example, I want to output red color in fragment shader.
HLSL:
return float4(1,0,0,1);
asm:
def c0, 1, 0, 0, 1
mov oC0, r0
How to implement this in AGAL?
mov oc, fc0
you have to pass in the red constant via:
context.setProgramConstantsFromVector(Context3DProgramType.FRAGMENT, 0, Vector.<Number>([1.0, 0.0, 0.0, 1.0]));
unfortunately, you can't define a constant in agal.