2d

Algorithm to find all points on a 2D grid some distance away from another point

最后都变了- 提交于 2019-12-05 06:14:13
I have some point on a 2D grid (x, y) and I need to find all points that are n distance away from that point. The way I'm measuring distance is by using the distance formula between the two points. Anyone know how to do this? Edit: Just for reference, what I'm trying to do is to write some AI path finding that will maintain some distance away from a target in a system that uses grid based locations. Currently I'm using A* path finding, but I'm not sure if that matters or makes a difference since I'm kind of new to this stuff. Here's what I would do: First filter out all points that are further

Java Tile Based Game Performance

时间秒杀一切 提交于 2019-12-05 05:23:05
问题 I am currently in the process of experimenting with a 2D tile based side scrolling game in Java, primarily based on the code and examples from "Developing Games in Java" by David Brackeen At the moment the map files are 100x100 tiles in size (each tile is 64x64 pixels). I have already configured the system to only display the tiles which are visible to the player. The Graphics system is managed by a ScreenManager class that returns the graphics object of the current BufferStrategy as follows:

Pygame camera follow in a 2d tile game [duplicate]

回眸只為那壹抹淺笑 提交于 2019-12-05 05:21:06
问题 This question already has answers here : Add scrolling to a platformer in pygame (4 answers) Closed last year . import pygame, sys from pygame.locals import * pygame.init() size = width, height = 480,320 screen = pygame.display.set_mode(size) r = 0 bif = pygame.image.load("map5.png") pygame.display.set_caption("Pygame 2D RPG !") x,y=0,0 movex, movey=0,0 character="boy.png" player=pygame.image.load(character).convert_alpha() while True: for event in pygame.event.get(): if event.type == pygame

Fitting 2D sum of gaussians, scipy.optimise.leastsq (Ans: Use curve_fit!)

若如初见. 提交于 2019-12-05 05:08:41
问题 I want to fit an 2D sum of gaussians to this data: After failing at fitting a sum to this initially I instead sampled each peak separately (image) and returned a fit by find it's moments (essentially using this code). Unfortunately, this results in an incorrect peak position measurement, due to the overlapping signal of the neighbouring peaks. Below is a plot of the sum of the separate fits. Obviously their peak all lean toward the centre. I need to account for this in order to return the

Adding the diagonal values in a 2d array

风流意气都作罢 提交于 2019-12-05 04:47:30
问题 I have the following 2d array int [][] array = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, {10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, {20, 21, 22, 23, 24, 25, 26, 27, 28, 29}, {30, 31, 32, 33, 34, 35, 36, 37, 38, 39}, {40, 41, 42, 43, 44, 45, 46, 47, 48, 49}, {50, 51, 52, 53, 54, 55, 56, 57, 58, 59}, {60, 61, 62, 63, 64, 65, 66, 67, 68, 69}, {70, 71, 72, 73, 74, 75, 76, 77, 78, 79}, {80, 81, 82, 83, 84, 85, 86, 87, 88, 89}, {90, 91, 92, 93, 94, 95, 96, 97, 98, 99}}; I have this code to find the sum of

Footprint finding algorithm

耗尽温柔 提交于 2019-12-05 04:40:23
I'm trying to come up with an algorithm to optimize the shape of a polygon (or multiple polygons) to maximize the value contained within that shape. I have data with 3 columns: X: the location on the x axis Y: the location on the y axis Value: Value of the block which can have positive and negative values. This data is from a regular grid so the spacing between each x and y value is consistent. I want to create a bounding polygon that maximizes the contained value with the added condition. There needs to be a minimum radius maintained at all points of the polygon. This means that we will

Cross product of 2 2D vectors

与世无争的帅哥 提交于 2019-12-05 04:26:37
Can anyone provide an example of a function that returns the cross product of TWO 2d vectors? I am trying to implement this algorithm . C code would be great. Thanks. EDIT: found another way todo it that works for 2D and is dead easy. bool tri2d::inTriangle(vec2d pt) { float AB = (pt.y-p1.y)*(p2.x-p1.x) - (pt.x-p1.x)*(p2.y-p1.y); float CA = (pt.y-p3.y)*(p1.x-p3.x) - (pt.x-p3.x)*(p1.y-p3.y); float BC = (pt.y-p2.y)*(p3.x-p2.x) - (pt.x-p2.x)*(p3.y-p2.y); if (AB*BC>0.f && BC*CA>0.f) return true; return false; } (Note: The cross-product of 2 vectors is only defined in 3D and 7D spaces .) The code

Obtain ordered vertices of GeneralPath

回眸只為那壹抹淺笑 提交于 2019-12-05 02:48:08
问题 How can I obtain the vertices of a GeneralPath object? It seems like this should be possible, since the path is constructed from points (lineTo, curveTo, etc). I'm trying to create a double[][] of point data (an array of x/y coordinates). 回答1: You can get the points back from the PathIterator . I'm not sure what your constraints are, but if your shape always has just one closed subpath and has only straight edges (no curves) then the following will work: static double[][] getPoints(Path2D

How to build a Tiled map in Java for a 2D game?

一曲冷凌霜 提交于 2019-12-05 02:16:47
问题 Not sure how to approach this problem. Basically, I want a Pixel -> Tile representation of a 400x400 window. Each coordinate on the screen, e.g 120x300 should be part of a tile. My smallest sprite is 4 pixels, so we can say that 1 tile = 4 pixels. The player and enemy sprites are all 20 x 20, so each player/bad guy will occupy 5 tiles. Then I want to use this Map class to: Retrieve the x/y coordinates of a player/monster sprite by suppling the index/id of the tile. Knowing where the

How to calculate end points of perpendicular line segments?

烈酒焚心 提交于 2019-12-05 02:06:36
I know the end points of a line segment and the distance/size of the perpendicular end caps I'd like to create but I need to calcuate the end points of the perpendicular line. I've been banging my head against the wall using either 45-45-90 triangles and dot products but I just can't seem to make it come together. I know the points in blue and the distance to the points in red, I need to find the points in red. Before marking as duplicate, I tried the answer posted in this question but it resulted in end caps which were always vertical. http://rauros.net/files/caps.png http://rauros.net/files