PostGIS - find circles a point is inside of - geolocation

I have a game. Players are points and Items are circles with varying radii. Players can add Items. Players must also see Items they are in range of.
When an item is added, it is pretty straight-forward to find all Players within the range of an Item.
When a player moves, how do I find all the Items they can see?

I'm not sure why I was confused, the answer is of course:
ST_Within(geometry A , geometry B) where A is the circle and B the point.
So given a circle centered at coordinates (0, 5) with a radius of 50 and a point at (3, 7), the query would be:
ST_Within(
ST_BUFFER(ST_GeometryFromText('POINT(0 5)'), 50),
ST_GeometryFromText('POINT(3 7)'))

Related

Center a generated Row in a SpriteKit Scene

I am making a Breakout Game and the Game generates rows from how ever many bricks I want in that row. But I cannot get the rows to start in the center. How would I achieve this, here is my current code.
I've tried numerous things, but the closest I got was to get them all to be in the middle, but the should spread out from the middle.
What I would like to achieve should look something like this.
If you have the maximum row size available, a simple way is to include an offset when you calculate the x coordinate.
let maxRow = ... // whatever the maximum row size is
let padding = (maxRow - row) / 2 // how many blocks to skip on the left
for i in 1...row {
// your block creation loop
let x = 15 + (i + padding) * Int(brick.size.width)
// make the brick at x, y
}
If things might not divide evenly (e.g., if maxRow is 15 like it seems to be in your pictures, but row could be 4) then you have to decide on what behavior you'd like. The above will keep bricks aligned because the integer division in calculating padding will truncate; the left and right padding won't be the same. If you use floating division and get a padding like 3.5, you'd get perfectly centered rows but odd rows and even rows would have different alignment.
If your problem is that you want things to appear in an animated way (like in your picture), then things are more complicated. Instead of generating based on the sequence 1, 2, ..., row, it's probably easier to think about generating from the sequence 0, +1, -1, +2, -2, ... After generating the center brick, you'd do the generation of additional bricks in pairs. The x coordinates would be calculated as xCenter + i * Int(brick.side.width).
You're adding the bricks into a parent SKNode (using addChild(_:)). Everything added in that parent node is relative to its coordinate space.
Try adding a brick at y: 0 and see where will it be positioned. If your scene has the anchorPoint at 0.5, you will likely see the brick in the center of the screen. From there, you go up or down (positive or negative y values) to show other rows.
To better understand how the coordinate system works, see About SpriteKit Coordinate Systems.
It's the same for the x axis. If your bricks start from left to right, that means the parent node has its origin to the left of the screen.
To start from the middle, you need to know the middle point. One option is to make a container node, position that in the center of the screen, and add all the bricks there. Like that, the bricks can start at (0, 0).
let middle = CGPoint(x: scene!.size.width / 2, y: scene!.size.height / 2)
let container = SKNode()
container.position = middle
// inside makeBricks(), add everything inside container:
container.addChild(brick)
It really depends on how you set up your node hierarchy.

How to tell if the lowest point in the output of BoxPoints(rect) is the bottom right or bottom left point of the bounding box?

In answer to another question, Sushanth stated:
The lowest point of the rectangle(does not matter left or right) will always be the first sub-list of the "box" ndarray. So in the example I have given, the first sub-list [169 144] represents the "bottom right of this rectangle".
Now this point will be the reference point to decide what the next sub-list represents. Meaning, the next sub-list will always represent the point that you first get when you move in the clockwise direction. (as shown in the second image of the for loop)
I don't understand how to tell if the lowest point is the bottom-left or bottom-right point on the bases of the "first sub-list".
I need to create a generalized code that can tell them apart so that I can reliably apply warpAffine transformation to a dataset of images (as shown here).
This is Sushanth's answer to my question:
To determine whether it is a bottom-left or right in a scenario when
the two bottom points have the same y-coordinate: i. First, have a
conditional statement to see whether the two bottom points have the
same y-coordinate. ii. If the condition is True, then check which
coordinate has the lowest x-value(or the highest). The coordinate
with the lowest x-value will be bottom-left of course! "How did you
determine this just by looking at the sub-list?" -- I did not
determine it by just looking at it! I could not! This is exactly why I
wrote the above for-loop in my answer!
with minor spelling corrections from my side
I learned later on that I actually didn't need that information for performing warpAffine transformation as the angle information is returned by minAreaRect
def warp_contour(img,cnt):
rows, cols = img.shape
rect = cv2.minAreaRect(cnt)
center,_,angle = rect
box = cv2.boxPoints(rect)
box = np.int0(box)
rot = cv2.getRotationMatrix2D(center, angle, 1)
img = cv2.warpAffine(img, rot, (rows,cols))
return img
But I won't be accepting this answer as I still want to know how to tell them apart.

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)

iOS SDK Triangle ASA or AAS (angle-side-angle or angle-angle-side) formula

I am looking to spin a UILabel 45 degrees (to the right) on it's anchor point (the center of the UILabel) and put it on the right of the table cell so it looks like a diagonal ribbon across the table cell, from the bottom-right of the cell up and toward the left until it hits the top of the cell.
To do this (in a diagonal) I do the following:
Get the height of the table cell. This gives me (in an triangle with sides a,b,c) "c". So, "c" is one leg of the triangle. Because I want it to be a 45 degree triangle that also gives me leg "a" of the triangle.
Now the easy part: I know all three angles of this triangle. "C" (angle across from side c) is 45 degrees, "B" (angle across from side "b") is 90 (cos it is the right top corner of the cell's content view...and we know those are right-angles. Angle "A" (angle across from side "a") is also 45.
Side "b" is the side i am having fits with... What formula do i use to get length of side "b" such that it is wide enough to go (when diagonal) across the height of the cell's contentview from the bottom right until it hits the top of the cell? I know for a 44pt high cell, the length of this UILabel when diagonal should be around 60-ish pts...but the formula is escaping me.
When using a online calculator Triangle Calculator and using the drop-down for angle-angle-side, I feed in the following numbers: A: 45,B: 45, C: 44, and this gives: 62.2254 for the side length...which is fine...but my table cell is not always 44pts high so i need a formula i can put in objective-c. I have read up on the Law of Sines, but my High-School Trig years are SO behind me.
I hope all this is clear. If not, please let me know. Thanks in advance.
If I understand you correctly you will always have triangle with one right angle and two other 45 degrees. If short side (both of them will have same length) of such triangle is X, then long side is square root from 2*X*X

Resources