2d

Data Structure for Spatial Agent Based Modeling [closed]

匆匆过客 提交于 2019-12-03 14:54:05
What are some good data structures for keeping track of agents in a two-dimensional, spatial simulation? I've seen some references to quadtrees (which I understand) and kd-trees (which I don't understand very well). I'm looking for something through which an agent can efficiently say, "I know my location, and I would like to know which agents are near me (within a certain radius of myself)." Examples (pseudo-code is fine) would be greatly appreciated. I'm working in Java. Well, I'm not sure exactly how it is implemented, but the MASON toolkit uses a discretization algorithm that places agents

Getting started with a Tile-based game in Qt using QGraphicsScene and QGraphicsView

雨燕双飞 提交于 2019-12-03 13:11:54
I'm going to start programming a 2D tile-based game in Qt and read about the QGraphicsScene and QGraphicsView classes which are intended for displaying and handling lots of 2D objects. My question is that will it be feasible to create a world with lots of tiles using QGraphicsScene? Can I add the whole world at once tile-by-tile or should I try to implement something to restrict the area a bit? I've read that QGraphicsScene can handle "thousands of items" but a 2D tile map can easily get really, really big (200x200 tiles? not that many, but that's already 40,000 objects which is a lot). The

2d Sprite Animations without using XNA or other third-party libraries

谁说我不能喝 提交于 2019-12-03 13:11:36
问题 I want to create a simple game, similar to what can be created with RPG Maker. What I am primarily looking for at the moment is a tutorial which can guide me on how to accomplish it without using XNA or any other specific library. The ideal would be a step-by-step tutorial or a good, easy-to-understand example. My goal is to do it on my own, and come to an understanding of how the overall process works with regards to animation elements relating to one another. I've already built a simple

How does Matrix.postScale( sx, sy, px, py) work?

元气小坏坏 提交于 2019-12-03 13:09:10
First read Taig's question Taig said: When calling Matrix.postScale( sx, sy, px, py ); the matrix gets scaled and also translated (depending on the given point x, y). That predestines this method to be used for zooming into images because I can easily focus one specific point. The android doc describes the method like this: Postconcats the matrix with the specified scale. M' = S(sx, sy, px, py) * M At a first glance this seems ridiculous because M is supposed to be a 3x3-Matrix. Digging around I've found out that android uses a 4x4-Matrix for its computations (while only providing 3x3 on its

Wrong rectangle size in canvas

江枫思渺然 提交于 2019-12-03 12:37:05
I'm implementing a color picker. There is problem with the rendering. When I call c.fillRect(0, 0, 100, 80); the size of that rectangle is 103x42 px instead of 100x80. What is wrong here? Also, rectangles are antialiased. Do I need offset the position by (0.5, 0.5) to avoid AA? I didn't use any kind of the coordinate system transformations. colorSlider = function($e, color) { this._$canvas = $('<canvas></canvas>'); this._c = this._$canvas[0].getContext('2d'); this._color = color || { r: 0, g: 0, b: 0 }; this._$canvas.width('310px'); this._$canvas.height('80px'); $e.append(this._$canvas); this.

Area covered by a point cloud with R

限于喜欢 提交于 2019-12-03 12:28:36
I have a cloud of points scattered in a 2D Euclidean space. I would like to calculate the area inside the polygon linking the most extreme (=peripheral) points of the cloud. In other words, I would like to estimate the area covered by the cloud in this space. Is there a formula in R? Thanks a lot for any response Julien This is called the convex-hull problem; R built-in chull function should do the work. To count area, you may use a formula from here . EDIT: Even better; splancs package has areapl function. So the function solving your problem should look like this: cha<-function(x,y){ chull(x

Working with the coordinate system and game screen in Unity 2d?

时间秒杀一切 提交于 2019-12-03 11:52:40
问题 So I've developed games in other platforms where the x/y coordinate system made sense to me. The top left representing the game screen with coordinates of (0,0) and the bottom right was (width,height). Now I'm trying to make the jump to Unity 2d and I can't understand how the game screen works. If I had a background object and a character object on the screen, when I move the character around his x and y values vary between -3 and 3... very small coordinates and it doesn't match the game

c# - how to move point a given distance d (and get a new coordinates)

孤街浪徒 提交于 2019-12-03 10:48:33
问题 Hi I was wondering if there is any efficent way to calculating coordinates of point (which was moved distance d from it's original location). Let's say I have a point P(0.3,0.5) and I need to move that point random direction with distance d. So far I did it by random picking new x and y coordinates and I was checking if distance between old and new point equals d. I do realize that is't too eficient way to do that. How would You do it ?? 回答1: Given a point (x1, y1) , we want to find a "random

What's a good, simple, 2D rectangles-only collision detection algorithm?

一世执手 提交于 2019-12-03 10:42:08
I'm designing a collision detection game tutorial for young adults, so I want this to be as simple as possible to make it easier to explain. The requirements are very simple. The world is 2D and contains only rectangles (of arbitrary sizes). BSP and even quadtrees seems like it would be overkill (again, the emphasis is on simplicity) but I would like something more efficient than brute forcing through all n(n-1)/2 possible collisions. 2D, rectangles only, and simple. Can anyone point to an algorithm I can look up? Is a quadtree algorithm what I'm looking for? EDIT: Also, the rectangles will

Blurring in PyGame

我的梦境 提交于 2019-12-03 10:17:58
问题 I'm working on a short intro in PyGame, and I need to blur some static lines. After two days of searching, I can't find anything. Does PyGame have a built-in method to blur a shape or surface? Will I need to do it manually? What would be the best way to approach this? To clarify, I'm not looking for motion blur – I just need a simple in-place blur, almost like a glowing effect. Thanks in advance! 回答1: There's no built-in way to blur a Surface . Workarounds are: scale the Surface with pygame