Using the hexgrid and coordinates above, I am trying to find a consistent formula to calculate the distance between two hexes.
Switched from my x,y to q,r,s coordinates by
q=x
r=y-(x+(ISODD(x)))/2
s=-r-q
then used this formula:
=max(abs(q1-q2) + abs(r1-r2) + abs(s1-s2)) / 2
hopefully this helps someone using an even-q grid
Related
I am using core plot to generate graphs for some NUMBERS vs dates, I want to start labels on y from minimum NUMBER(or close to minimum) like IMAGE 1.
I landed up in doing this with range.
plotSpace.yRange = CPTPlotRange(location:minimumValue-10,length:maximumYaxisValue-minimumValue+20)
All i want to do is to get the minimum NUMBER as the starting label on y-axis (or close number like in image 1)
I have tried many things but nothing worked out, any help is greatly appreciated. Thank you :)
I am having issues with my implementation of CorePlot. I have a subview in my UIViewController than contains the chart. Most of the data shows up fine but no increments / values are showing up on the y axis.
This is what I am seeing now:
If I shift the x axis start point by subtracting 10 (to better see the left half of the chart) I see this:
For the record, I do not have any values outside of the (positive x, positive y) quadrant on the chart and have logged out my data to verify this. Any input / advice would be appreciated, thank you!
http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2
This guy does a great job explaining that about halfway down... search for "You're Getting There!" to find exactly where he talks about the weird lines in the Y axis.
Hope this helps!
Set the leftPadding on the graph.plotAreaFrame to leave room for the axis labels at the left side of the graph.
The smeared y-axis is caused by too many tick marks and labels—they overlap and become illegible and negatively impact drawing performance. You need to adjust the labeling parameters to reduce the number of ticks and labels. By default, the axis draws major tick marks and labels one unit apart. The properties that need to be changed depend on the labeling policy you want to use.
I am developing an Area chart like the following and facing the following issue.
curve shape is not looking proper, i need a smooth curve.
X-axis values are Dynamic, it May start with 40 or May be 60 or
any other value.how to calculate that ?
Any Help will be greatly Appreciated.
To make the line smoother, either give it more data points or make a curved plot.
plot.interpolation = CPTScatterPlotInterpolationCurved;
If you know the range of data values, just set the xRange directly. Remember to set the location to the min value and the length to (max - min). You can also have the graph scale the plot space for you.
[plotSpace scaleToFitPlots:[graph allPlots]];
ok here is the problem:
I want to show to my users the closest geopoints in his vicinity.
i have arround 55.000 fixed geopoints which could be shown. (I have for all of them long/lat)
dependent on the users location (long/lat) i want to show the closest 20 geopoints.
so of course i could just calculate all 55.000 geopoints and see if there are 20 within a certain radius of the users lang/lat and rank them afterwards but this would be somehow an overhead to calculate always 55tsd geopoints.
is there a posibility to "add" 5-miles/kilometers range to a users long and lat and calculate only the distance for those which are within this radius?
i hope you get what i mean. :)
Merci
If the calculation of distance between all points take too much time, you could narrow down the possible points just by simple difference between lat/lon (source_lat - target_lat) (source_lon - target_lon) and take only the closest point to final calculation of distance. You could use formula to calculate distance.
D = 60* 1.1515 * acos (sin(pi*y/180) * sin(pi*Y/180) +
cos(pi*y/180) * cos(pi*Y/180) * cos((z-Z) *pi / 180)
) * 180 / pi)
But the efficiency of calculation depends on used database technology as well.
I am using meshm to plot densities.
How do I calculate the center point for each of the bins? I want to associate the data in m with the centerpoints I have looked at the source code of meshm and believe the solution will be a modified version of meshm that returns the latitude and longitudes of each bin's center point.
meshm calls the function meshgrat which returns the latitude and longitude points of the mesh that will be plotted by surfacem. The problem is that the lat and lon matrices are not the same size as m. I need to match the latitude and longitude points with the density data in m I believe I need to scale the data based on GRATSIZE a variable in meshgrat.
NOTE: meshm is part of the Matlab Mapping Toolbox
NOTE NOTE: This is a follow-up question to Determine distance from coastline in Matlab
You can get the edges of the mesh using MESHGRAT, which is the function called by meshm when it makes the grid for binning.
%# create the mesh that is used by meshm
[latgrat,longrat] = meshgrat(m,termaplegend);
%# find the latitudes of the center points
latPts = (latgrat(1:end-1,1:end-1) + latgrat(2:end,1:end-1))/2;
%# find the longitudes of the center points
lonPts = (longrat(1:end-1,1:end-1) + longrat(1:end-1,2:end))/2;
The center of the bin in 2nd row, 5th col is [latPts(2,5),lonPts(2,5)].
Within meshm just modify the inputs to meshgrat:
[lat,lon] = meshgrat(Z, R, gratsize); % original
[lat, lon] = meshgrat(Z,R); % modification
By default, gratsize = [] which in meshgrat will return the default graticule size of 50 X 100. By not passing in gratsize, the graticule is set to the same size as Z.