How to get the real bounding box in the static images API MAPBOX? - mapbox-api-staticimages

With the MAPBOX Static Images API is possible to download an static image. If I give a center coordinates, a zoom and the dimensions (in pixels) of the image the api returns the static image.
How can I get the real coordinates of the bounding box of the resulting image? Or, is possible to convert the pixels (width x height) of the image to meters to be able to calculate the coordinates of the bounding box?
Thanks

Related

Get scaled coordinate of webcam capture

I want to implement a website with webcam video capture and get the coordinates when user clicked on a point on the capture.
But since webcam resolution is different and I also want a static dimension (720px * 480px) of the video element.
How can I do this?
e.g. Video element with 720px width and 480 height, with 1920 x 1080p camera.
Expect: I click on 720*480 video element, return with x, y coordinate corresponding in 1920 * 1080 dimension

Sprite alignment in a Sprite Packing C application

I am creating the "perfect" sprite packer. This is a sprite packer that makes sure the output sprite is compatible with most if not all game engines and animation software. It is a program that merges images into a horizontal sprite sheet.
It converts (if needed) the source frames to BMP in memory
It considers the top-left pixel fully transparent for the entire image (can be configured)
It parses the frames each individually to find the real coordinates rect (where the actual frame starts, ends, its width and height (sometimes images may have a lot of extra transparent pixels).
It determines the frame box, which have the width and height of the frame with the largest width/height so that it is long enough to contain every frame. (For extra compatibility, every frame must have the same dimensions).
Creates output sprite with width of nFrames * wFrameBox
The problem is - anchor alignment. Currently, it tries to align each frame so that its center is on the frame box center.
if((wBox / 2) > (frame->realCoordinates.w / 2))
{
xpos = xBoxOffset + ((wBox / 2) - (frame->realCoordinates.w / 2));
}
else
{
xpos = xBoxOffset + ((frame->realCoordinates.w / 2) - (wBox / 2));
}
When animated, it looks better with it, but there is still this inconsistent horizontal frame position so that a walking animation looks like walking and shaking.
I also tried the following:
store the real x pixel position of the widest frame and use it as a reference point:
xpos = xBoxOffset + (frame->realCoordinates.x - xRef);
It also gives a little better results, showing that this is still not the correct algorithm.
Honestly, I don't know what am I doing.
What will be the correct way to align sprite frames (obtain the appropriate x position for drawing the next frame) given that the output sprite sheet have width of the number of frames multiplied by the width of the widest frame?
Your problem is that you first calculate the center then calculate the size of the required bounding box. That is why your image 'shakes' because in each image that center is different to the original center.
You should use the center of the original bounding box as your origin, then find out the size of each sprite, keeping track of the leftmost, rightmost, topmost and bottommost non transparent pixels. That would give you the bounding box you need to use to avoid the shaking.
The problem is that you will find that most sprites are already done that way, so the original bounding box is actually defined as to the minimum space to paint the whole sprite's sequence covering these non transparent pixels.
The only way to remove unused sprite space is to store the first sprite complete, and then the origin and dimensions of each other sprite, like is done in animated GIF and APNG ( Animated PNG -> https://en.wikipedia.org/wiki/APNG )

How to map CALayer texture to cube so text in layer show up correctly?

I am adding a CALayer to a SCNBox geometry contents... It works and I see this:
I want to be able to see the text on the box correctly. I understand that the texture is now applied to the geometry etc...
How can make it so the text I write in the CALayer shows up horizontally around the box...?
the default UVs (or texture coordinates) of an SCNBox are such that the same content is displayed on each side. You will have to rebuild a geometry with new texture coordinates so that the pattern does not repeat. You can start from scratch, or build an SCNBox and retrieve its geometrySources.

Plot a known pixel (x,y) from original image using custom Bing Maps WPF tiles

I am trying to use the Bing Maps WPF control to render custom map tiles from an image of a fictional game world map, but I also need to plot X,Y values on the map from the original world image (sort of like an in-world GPS).
The image is 5720x5720 and I already have working (in a different application) a function that manually crops, scales and redraws sections of the image and plots the pixelX and pixelY coordinates in a PictureBox. I would like to get the same functionality working using the map control.
I used this Photoshop plugin to cut the tiles from the original custom image (works like maptiler for google mapes)
https://github.com/bramus/photoshop-google-maps-tile-cutter/
The problem is I know the X,Y values to plot from the original image, but I'm not not quite sure how to calculate Lat/Long for drawing a point in the custom tile system.
<m:Map Name="Map">
<m:Map.Mode>
<!-- set empty map mode, i.e. remove default map layer -->
<m:MercatorMode/>
</m:Map.Mode>
<local:MyTileLayer UriFormat="file:///C:/map_tiles/{z}_{x}_{y}.jpg"/>
</m:Map>
The map is displaying great and everything looks fine using the custom map tiles. I found this link that provides a class for converting PixelXY to LatLong in the TileSystem, but they are all for realistic world points.
https://msdn.microsoft.com/en-us/library/bb259689.aspx
My custom map tiles are actually for a fictional map for a game so I don't believe the projection and earth-curvature calculations are needed in my situation.
How might I go about plotting a point accurately in the Bing Maps WPF control if I only know the X,Y pixel coordinates from the original untiled image?
Given that your 5720x5720px map image covers the standard Bing Maps (or Google Maps or OpenStreetMap) coordinate range of longitude = -180..180 and latitude = -85.0511..85.0511, the following method would convert from image pixel coordinates to lat/lon according to the Mercator projection:
public static void PixelXYToLatLon(
double pixelX, double pixelY, out double latitude, out double longitude)
{
var imageSize = 5720d;
var maxLatitude = 85.05112878; // = Math.Atan(Math.Sinh(Math.PI)) / Math.PI * 180d;
var y = (0.5 - pixelY / imageSize) * (2d * maxLatitude);
latitude = Math.Atan(Math.Sinh(y * Math.PI / 180d)) / Math.PI * 180d;
longitude = (pixelX / imageSize - 0.5) * 360d;
}
The imageSize variable might of course also be a method parameter.
If you use MapTiler (http://www.maptiler.com) to create the tiles you have two ways how to achieve what you want:
A) Map your game map to the artificial world with Lat/Lon coordinates
In this case you will map the world coordinates to your pixel coordinates. The tiles must be prepared in a correct way, same as those for real world maps.
To create the tiles with MapTiler you should follow this steps:
Choose "Mercator tiles" in the first step
Drop in your image file
Choose "Web mercator (EPSG:3857)" in the dropdown in the "Coordinate system" dialog - it is a square image of the whole world and you don't want to deform it.
Choose "Bounding box (West South East North)" in the dialog "Geographical location" and copy&paste in the input the world coordinates: "-20037508.342789244 -20037508.342789244 20037508.342789244 20037508.342789244"
Render the tiles
With this approach you can load the tiles in your Bing Maps WPF control and position the markers or other data by using Lat/Lon coordinates.
The point [0,0] is going to be center of the image, and you can calculate the other lat/lon coordinates appropriately.
See this page and source code down on the page:
http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
The globalmaptiles.py code embedded in the page is available in different languages including C# (.cs) if you need it. It has been ported by other people from our code.
B) Stay in raster coordinates
A different approach - where you create the map tiles in the original raster coordinates of the input file. There are no Lat/Lon involved, coordinate system is in pixels and you can draw markers and polygons in pixel coordinates as well. MapTiler gives you sample JavaScript viewer in Leaflet and in OpenLayers. Other viewers you have to patch yourself for using with pixel coordinates. To generate the tiles just choose "Raster tiles" - as in this tutorial: http://youtu.be/9iYKmRsGoxg?list=PLGHe6Moaz52PiQd1mO-S9QrCjqSn1v-ay
I expect the tiles made with your Photoshop plugin are going to be similar to the raster coordinates made with MapTiler.

Getting Relative Position of a Rotating Camera

I have a Viewport3D with a 3D model composed of multiple smaller components centered at the origin. I'm animating the PerspectiveCamera to rotate about the Y-axis using an AnimationClock created from a DoubleAnimation to create a rotating effect on the model. In addition, I have another rotateTransform3D assigned to the camera's transformgroup to enable the user to orbit around and zoom in-out of the model using the mouse.
I want to be able to translate each component as it is being selected to move in front of the rotating camera. However, I don't know how to get the position of the camera relative to the 3D model because the coordinate system of camera is being animated and transformed by the user's input.
Is there a way to get the offset between two coordinate systems?
Any help or suggestions would be appreciated.
Thanks,

Resources