Rotating an NSView and getting its corner points - cocoa

I am rotating an NSView using:
setFrameRotation:
Which rotates the view around its bottom left corner. What is the best way to rotate a view around its center point?
Also, i want to get the points in the superview of its corners. Using:
view.frame.origin
Just gives me the corner before i rotate it. How would i get the actual points of its corners once it has been rotated?
Thanks in advance, Ben

To get an effective rotation about the center of the frame, you have to translate the frame's origin.
Also, of course view.frame.origin gives the origin before you rotate it. It's also giving you the origin after you rotate it, because the rotation is around the origin. The origin isn't moving. If you do translate the origin to get rotation around the center, you'll then know the new origin.
To get the other corners, you'd use [view convertPoint:pt toView:view.superview], where pt is each of the corners in the view's coordinate system. E.g. NSMakePoint(NSMaxX([view bounds]), NSMinY([view bounds])).
You can actually use this technique to obtain the translation you want. Compute the desired center of the view, or just record the current center if it's where you want it. Then rotate the view. Obtain the new location of the center using -convertPoint:toView:. Then translate the origin by the difference between the new center and the desired center.

Related

MapLibre GL JS with terrain layer: How to pin a horizontal plane to a specific altitude?

I based some code on the "Add a 3D model" example at maplibre.org in order to draw only a horizontal plane on a map which uses setTerrain to add a terrain layer.
My intention is to draw a couple of semitransparent layers at a given heights above sea level and have them intersect with mountains, somewhat similar to contour lines.
In my first test I just created a 1km-wide square at altitude 0.
I am somewhat confused by the behavior, since altitude 0 turns out to be the height of the terrain in the center of the visible map area. When I then drag the map and release the mouse, altitude 0 gets somehow reset again to the new altitude 0 of the terrain at the center, making the plane change its relative altitude.
The following animated GIF illustrates the problem:
The GIF has a mountain range to the right and the elevation is greatly exaggerated, in order to better illustrate the issue.
What do I need to do in order to be able to specify the height of the plane in meters above sea level and have it appear to be fixed at that height when dragging the map?
I think I need to get the height of the terrain at the center and then add/substract it from the plane's z-position in order for it to stay put at the height relative to given landmarks, but I have got no idea on how to do this inside of a custom layer's render function.

Set object center position at world origin

I loaded a .obj earth and I'm trying to perfectly center it to the world origin. By "center it to the world origin" I mean I want the object exact center to be at the world exact center (0, 0, 0).
I know I can use a bounding box to get the center of the object and then maybe translate the whole object by minus that amount but is there a simpler way to do this ?
When you add a mesh to a scene, it is automatically added at the origin.
The bounding box way is non-destructive to your geometry, so if your shape has an offset built into it, you won't lose that. It's also "easy" because a majority of the processing is in finding the bounding box initially, and then that box doesn't change unless you scale or deform the shape.
There is an alternate way, if you don't mind your geometry changing: mesh.geometry.center(); will shift all the vertices such that the shape's geometric origin is at the mesh's origin (and if your mesh's origin is already at the scene origin, then you're good to go).

Calculate GPS location with center point

I got one center point GPS such as(32.112342,112.223123)
and I got radius 10(km)
I can draw a circle with these information
Here I have one new requirement
I need fix this circle with little Hexagon.
and the center Hexagon must be the the center of the circle
how can I get all those little Hexagon's center point GPS location
Thans
Suggest you to try with Graphics2D as provided in java.awt package.
You can use its drawPolygon() and fillPolygon() methods.

Button on Graph point in Core-plot? Objective-C

I'm currently working on a project where I present several circles in a graph, where some circles are dependant others. I have 1 circle which has its origin in (0.0, 0.0), and another circle (let's call them circle1 and circle2) which has its origin on an angle position on circle1. So I calculate the origin position of circle2 by deciding an angle and calculate that angle towards circle1's local graph. By doing this I get an x and y position for a specific angle in the local graph for circle1. On the point (x, y) I then draw circle2.
However, I would like the user to be able to interact with circle2. More precisely I want to be able to change the angle from which circle2 was drawn by adding some sort of slider, which on the user drags in order to change the angle and then redraws the circle2.
Clarification: What I want to do is to add a button to the HostedView and drag it around in the view. Is this possible in Core plot?
You can't add buttons or other views to the Core Plot hosting view. Add it to the hosting view's parent view and position it on top of the hosting view.

rotate a projection to follow mouse drag

I'm working on a project to generate world map projections and manipulate them. You can see a beta version here : http://ansichtssache-n.ch/en/personas/daVinci
I'm trying to get the drag event correctly interpreted, so that for example when you drag Australia up, it actually moves Australia up and not the center of the projection (causing Australia to move down in a Miller projection).
I've been trying to find the correct rotation angles to apply to the 3 axis as shown here http://bl.ocks.org/mbostock/4282586 .
I can get the x/y position on the canvas from the start and end of the mouse drag, I can get the geo-coordinates of these points too, and I can get the x/y of the current center as well as its geo-coordinates, but honestly I'm stuck now...
Any idea ?
I had a similar problem here Compose two rotations in D3 geo projection?
I came up with a way to compose the trackball rotation with the existing projection rotation so that you get intuitive control regardless of the original globe orientation.

Resources