Pinch Zooming X and Y axes independently (Non uniformly) with Core Plot - core-plot

I am using Core Plot to show graphs in my application and I want the Pinch Zooming feature to scale the X and Y axes independently. When pinch Zooming, the gesture should generate one X-pinch-component and one Y-pinch-component that should scale the axes differently.
If the user's two fingers are on a straight vertical line, the graph should only be scaled on the Y axis.
If the user's two fingers are on a straight horizontal line, the graph should only be scaled on the X axis.
If the user's two fingers are on a straight line between 01.30 and 07.30 on a Clock (45 degrees), the graph should be scaled equally on the X and Y axis - I hope you get the idea.
How can this be achieved? Core Plot always scales my plot equally on X and Y, regardless of how the user's fingers are placed.\

Turn off the built-in pinch handling (allowPinchScaling = NO on the hosting view) and provide your own gesture recognizer to get the interaction information and compute the scaling angle.

Related

Imported blender model rotates incorrectly

I've imported a Blender 3D model (a sphere with an Earth texture) in SceneKit, and I'm trying to rotate it through a pan gesture. I have to mentally swap the x and y axises, because the rotation system in SceneKit is different from the one adopted by Blender.
This is how I rotate the Earth object:
func pan(gesture:UIPanGestureRecognizer)
{
let translation = gesture.translation(in: self.view) * 0.05
let intensity = Float(magnitude(point: translation)) // Euclidean distance
let rotation = SCNMatrix4MakeRotation(intensity, Float(translation.y), Float(translation.x), 0.0) // I invert the x and y because of the different coordinate system
earth.transform = SCNMatrix4Mult(earth.transform, rotation)
gesture.setTranslation(CGPoint(x:0.0, y:0.0), in: self.view)
}
The rotation around the y axis is correct, but if I try to rotate it along the x axis by panning vertically, it seems like if the x axis of the Earth is oblique and not perpendicular with the y axis.
In this video I first drag the finger upwards and then downwards:
https://www.youtube.com/watch?v=7YumAB_rXlk
When you rotate the node with a gesture, it is done with respect to the node's axes. Say your node is in it's original default orientation, +X direction to the right. Now you rotate the the node 180° about the Y with a left-to-right swipe. If you now apply a top-to-bottom swipe, the node will rotate upward about the X instead of downward. This is because the first swipe swung the X-axis around such that it was pointing in the opposite direction. That's just the extreme example, if your first Y rotation was less than 180°, an attempt to now swipe about the X will cause the node to rotate in a slanted manner such as in your video.
One way to deal with this is to place your earth node in another node (a "container node"). Use the earth node for Y rotation and,separately, use the container node for the X rotation.
But the way I deal with this can be found here: How to rotate an SCNBox

How to get pinch scaling data for x and y axis

I've seen the UIPinchGestureRecognizer and how it can be used for a single scale variable, but is there a way to get individual scales for the x and y axes?
There is no simple way to do that with UIPinchGestureRecognizer. Maybe by subclassing UIPinchGestureRecognizer or directly UIGestureRecognizer you could do it, but this is going to be hard.
The easiest way is to add a UIRotationGestureRecognizer. Then knowing the rotation and scale you can compute the scale for each axis by doing a projection.

ios Core plot - scatter plot circles overlap with x, y axes

I am currently plotting certain data using Scatter Plot of Core Plot. The size of the circles depends on the frequency of occurrence of the particular value. On plotting, I find that some of the circles are overlapping and crossing the x and y axes.
Is there any method to check if a circle (i.e, plot point) crosses the axes and automatically resize the circle so that it does not cross the axes?
Edit - The axes are fixed. So I cannot change the axes.
Edit - I would like to know which methods to use to determine if a circle crosses/touches the x or y axis. Currently the circle overlaps if the size of circle is 12 and its y coordinate is 1.1. I am unable to understand how the size is being mapped to the circle on the plot. Thanks.
No. The easiest way around this problem is to figure out how big the largest circle will be and adjust the plot ranges on the the plot space to leave at least that much space between the extreme data points (smallest and largest) and the axes or other edges of the plot space. The plot space has methods to convert back and forth between data coordinates and pixels in the coordinate space of the plot area layer.
The point conversion methods are:
(data to plot area)
-(CGPoint)plotAreaViewPointForPlotPoint:(NSDecimal *)plotPoint
numberOfCoordinates:(NSUInteger)count;
-(CGPoint)plotAreaViewPointForDoublePrecisionPlotPoint:(double *)plotPoint
numberOfCoordinates:(NSUInteger)count;
(plot area to data)
-(void)plotPoint:(NSDecimal *)plotPoint numberOfCoordinates:(NSUInteger)count
forPlotAreaViewPoint:(CGPoint)point;
-(void)doublePrecisionPlotPoint:(double *)plotPoint
numberOfCoordinates:(NSUInteger)count
forPlotAreaViewPoint:(CGPoint)point;
Depending on your application, you might be able to expand the plot range by a simple factor using -expandRangeByFactor:. You can find the factor for the xRange by dividing the width of the plot area plus the circle diameter by the width of the plot area. Do a similar calculation for the yRange using the height of the plot area.
Perhaps you could check to see if half of the diameter is greater than both the x and y value of the plot. If it is greater, then reduce the diameter to equal twice the smaller of x and y.

Why does DirectX use a flipped Y axis?

I am saving my driven X/Y coordinates, and then using a function that convert the coordinates to meters, and add 1280 to each point (so it will fit nicely into a 2560x2560 image), and then draw a polygon between the 'points', resulting in a some sort of racing line. But once I have generated the polygon and saved it as an image, it is vertically flipped somehow. Flipping the image vertically will make it match the track bitmaps perfectly. I was told this is due to DirectX internally has the Y axis flipped. Why does DirectX use a flipped Y axis?
Well, the question is, does DirectX have a flipped Y-axis or does the image?
DirectX uses a 3D/4D coordinate system where the X-axis points to the right and Y-axis points upwards when no transformation is applied. This is because the screen (where Y-axis points downwards) is the last instance that has to process the image. Every step before that uses the coordinate system with the upward Y-axis. Since Direct3D is designed for 3D worlds, a coordinate system that is aligned like the world and like most coordinate system in maths is much more convenient for the programmer and designer. Imagine, you would create a 3D model. Wouldn't it be kind of weird, if you design it so that the Y-axis is pointing downwards?
When you have no transformation at all that would allow perspective and so on, you have the same coordinate system. Ignoring the Z-axis, the top left corner is (-1 | 1), the bottom right corner is (1, -1). This is equal to the coordinate systems used in e.g. maths. In the end, this coordinate system is transformed with the viewport which will result in the top left corner to be (0 | 0) and the bottom right corner to be (ResolutionX | ResolutionY).
So all in all, the reason why the Y-axis points upwards is that Direct3D's main purpose is to describe worlds in a convenient way independently of the screen's physical attributes.

drawing overlapping circles in corona

How to draw a circle overlapping another circle in the moved phase of touch event,such that no gap is left out between the circles.The circles must be tightly packed to one another,so that even when user moves his hand on the screen faster or lightly,no gap must be present between the circles.
Just two circles? Or many circles? If just two, then detecting if they overlap is simply verifying that their centers are not closer than the sum of their radii. For example, if Circle1's raduis is 10 pixels, and Circle2's radius is 25 pixels, then they overlap if the center of Circle1 is less than 35 pixels from the center of Circle2.
So if you do your calculations in the "moved" phase and find that they're too close, you have to adjust the position of one of them. How you go about that will depend on the specifics of your application. You could:
Keep the y coordinate of the moving circle the same, and calculate the necessary x coordinate to maintain the required distance.
Same as above but swap x and y.
As above, but move the "unmoving" circle away from the "moving" circle.
Some other calculation that makes sense for your application.
NOTE: You should accept some of the answers you've been given.

Resources