How to set where 0,0 coordinates are? - lua

By default, 0,0 coordinates are in the top, left corner. However, for my scene, it would be very helpful if it was in my bottom, left corner.
Is that even possible? If so, how can I set that?

This is a mathematical approach which I think is a lot easier.
Simply define a function which converts your local Y coordinate to what Corona uses:
function localY ( y )
return 600-y --Assuming your screen size is 600 pixels
end
Then simply use
x, localY(y) instead of x,y
You can do the same for x if decided to change it.

Related

Roblox Lua Script, How to make a frame decrease its size from left to right?

I'm trying to make a health bar that decreases from left to right instead of from right to left
and it has to be this way because of how the interface looks, I've tried different calculations but all of them were close but too far and I'm running out of ideas on how to make it
Take a look into anchor point.
What anchor point does is set the origin of the UI. So for your use case, you'll probably want to set the anchor point to [1,0]. Which means the UI will scale to the left
(White Box) Anchor point 0,0
(White Box) Anchor point 1,0
With an anchor point of 1,0, it will scale to the left

In Geogebra, can you plot the abscissa (xAxis) vertically and the ordinate (yAxis) horizontally?

In GeoGebra, can you plot the abscissa (xAxis) vertically and the ordinate (yAxis) horizontally?
I need this, since I like to visualise an inverse. Since I also like to visualise an Area between different values, I need an IntegralBetween for an interval on y's (so re-interpreting x as y does not work). In addition the function is very tall, so I like to have the layout rotated by 90 degrees.
In GeoGebra's 2D view x always refers to the horizontal and y to the vertical axes. You can however shade the area between two functions in y using inequalities with zero line thickness

Is it possible to create a Q-Q plot when lacking a coordinate system?

I'm looking to create a Q-Q plot within Rascal using the Vis library. I have been told there is no positional system. Is this true? If true, how would I go about plotting this or any scatterplot? Does anyone have an example of this in use?
That's an excellent question. Certainly Rascal's Vis library is "point free" in the sense that its layout mechanism has no absolute coordinate system. However, there are certain Figure kinds which have a relative coordinate system wrt their own "origin". When you combine several of those using horizontal, vertical or overlay boxes (and align them properly), you can create the effect of bar charts, scatterplots and whatever you desire.
In particular the overlay Figure composition is interesting: http://tutor.rascal-mpl.org/Rascal/Libraries/Vis/Figure/Figure.html#/Rascal/Libraries/Vis/Figure/Figures/overlay/overlay.html
Figure point(num x, num y){ return ellipse(shrink(0.05),fillColor("red"),align(x,y));}
coords = [<0.0,0.0>,<0.5,0.5>,<0.8,0.5>,<1.0,0.0>];
ovl = overlay([point(x,y) | <x,y> <- coords]);
render(ovl);
Produces this (both code and image taken from the documentation linked above):
Each point is an ellipse which is aligned at the (x, y) position relative to the origin of the enclosing overlay box.
The origin by default of this overlay seems to be the upper-left corner, when no other FProperty's are given to the overlay. It's possible other alignment options for the overlay Figure also change the position of its origin.
With the help of Jurgen Vinju I wrote this code, hope it helps someone: https://gist.github.com/rlmhermans/c9e82a6a623b65f0c6957ab3ff2742cf

What do the coordinates mean in love.graphics.polygon

I don't know which numbers do what in the coordinates example here. I imagine they mean things like place the top left corner at this position and the bottom right corner at this position, but I don't know which number corresponds to which position.
I've been trying to fool around with the numbers to get a small green rectangle but keep getting weird results like the following, and don't know which numbers need to be what is order to make the rectangle symmetrical and at the bottom
This is what the rectangle should look like
The height of the rectangle is 50, the height of the screen is 1000, and the width of the screen is 1700.
Here's my draw function
function love.draw()
love.graphics.setColor(0.28, 0.63, 0.05) -- set the drawing color to green for the ground
love.graphics.polygon("fill", objects.ground.body:getWorldPoints(objects.ground.shape:getPoints())) -- draw a "filled in" polygon using the ground's coordinates
-- These are the grounds coordinates. -11650 950 13350 950 13350 1000 -11650 1000
love.graphics.setColor(0.76, 0.18, 0.05) --set the drawing color to red for the ball
love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius())
love.graphics.setColor(0.20, 0.20, 0.20) -- set the drawing color to grey for the blocks
love.graphics.polygon("fill", objects.block1.body:getWorldPoints(objects.block1.shape:getPoints()))
love.graphics.polygon("fill", objects.block2.body:getWorldPoints(objects.block2.shape:getPoints()))
print(objects.block1.body:getWorldPoints(objects.block1.shape:getPoints()))
end
As described at https://love2d.org/wiki/love.graphics, Löve's coordinate system has (0, 0) at the upper left corner of the screen. X values increase to the right, Y values increase down.
The polygon function expects the drawing mode as it's first parameter, and the the remaining (variable) parameters are the coordinates of the vertices of the polygon you wish to draw. Since you want to draw a rectangle you need four vertices/eight numbers. You do not have to list the upper left corner of the rectangle first, but that's probably the easiest thing to do.
So in your case, you want something like:
love.graphics.polygon('fill', 0, 950, 0, 1000, 1700, 1000, 1700, 950)
I've not worked with the physics system, so I'm not quite sure how it's coordinate system relates to "screen" coordinates. The values you show in the comment in your code listing seem like they should give a rectangle (although x = -11650 wouldn't be on screen). You might try experimenting without the physics system first.
Also, since the physics system in Löve is just a binding to Box2D, you might want to read its documentation (http://box2d.org/about/). Not really sure what you're trying to do with feeding shape:getPoints into body:getWorldPoints.

Convert Scene's (x, y) to screen's (x, y)

I have an application built with SceneKit that is currently displaying several nodes. I can figure out which node is pressed and want to use that to make a label appear below the Node that was touched. Now, when I set the label's center the following way...
nameLabel.center = CGPointMake(CGFloat(result.node.position.x), CGFloat(result.node.position.y+20)
…it appears in the upper left corner since the node is on (1, 0). What I figured is that the sceneView's (0, 0) is in the center of the screen while the actual physical display's (0, 0) is in the top left corner.
Is there a way to convert the two different numbers into each other? (I could hardcode since I know where the Node's are or create a separate label for each Node but that is not really a perfect solution.)
Thanks in advance :)
You can use the projectPoint: method:
var projected = view.projectPoint(result.node.position))
//projected is an SCNVector3
//projected.x and y are the node's position in screen coordinates
//projected.z is its depth relative to the near and far clipping planes
nameLabel.center = CGPointMake(CGFloat(projected.x), CGFloat(projected.y+20)

Resources