2d

Simplest 2D array, using g++, with one variable dimension?

独自空忆成欢 提交于 2019-12-14 03:14:49
问题 I would like to make an array like this: double array[variable][constant]; Only the first dimension is variable. Declaring this with a variable as the first dimension gives initialization errors. Is there a simple way to do this with pointers or other basic types? 回答1: Variable length arrays didn't make it in the latest C++ standard. You can use std::vector instead std::vector<std::vector<double> > arr; Or, to fix for example the second dimension (to 10 in this example), you can do std:

Detecting light projections and intersections in 2D space using C#

一曲冷凌霜 提交于 2019-12-14 02:35:19
问题 A light source is an entity in 2D space that sits in a single coordinate. There are multiple light sources around in various locations and each gives off 8 rays of light in directions N, S, E, W, NW, NE, SW, SE. The coordinates of all lights are known. I need to calculate all intersections of these rays within the grid. long width = int.MaxValue; // 2D grid width. long height = int.MaxValue * 3; // 2D grid height. List<Point> lights = a bunch of randomly placed light sources. List<Point>

How to determine +/- sign when calculating diagonal intersections between two points in 2D space?

只谈情不闲聊 提交于 2019-12-14 01:27:41
问题 This is an offshoot of another question and has to do with Keith Randall's answer to the problem. Please do have a quick look at the image there to see what the function below is trying to do. In short, any two points on a 2D grid would have two diagonal intersections if x2 != x1 and y2 != y1 . I implemented the following function but cannot figure out how to determine which cell to subtract delta from and which to add to. As a result, for some pair of coordinates, the results are accurate

Drawing lines in java (Graphics 2D)

十年热恋 提交于 2019-12-13 22:13:07
问题 I am trying to do a little program on Eclipse. The program goes like this: when I click for the 1st time on thr Panel on the frame, a line has to be drawn regarding the Y position of my mouse listener.The line takes all the width of the panel. On the 2nd click, another line has to be drawn, again regarding the Y position of where I clicked. After, I'll put a little circle between the 2 lines and make a little animation with it. But now, I have a problem. When I click on the panel, a line is

Add a vector to a position

戏子无情 提交于 2019-12-13 20:11:32
问题 I have an object in 2D space whose position is (A, B) and which has an orientation (between 0 and 360). I have a distance, say D. I would like to add D to the object's position, in the direction that the object is looking toward. Mathematically, how would I go about doing that? Thank you. 回答1: The result would be: (X,Y) = (A,B) + D*(cos(O),sin(O)) Edit: The vector equation is equivalent to: X = A + D*cos(O) Y = B + D*sin(O) 来源: https://stackoverflow.com/questions/22683302/add-a-vector-to-a

CanvasRenderingContext2D flip transformation

心已入冬 提交于 2019-12-13 19:11:12
问题 I found this CanvasRenderingContext2D and i played around a little bit with it. I was able to scale and to rotate my Image using this context: crop: function () { var canvas = document.createElement("canvas"); var context = canvas.getContext("2d"); canvas.width = this.options.width / this.scale; canvas.height = this.options.height / this.scale; var currWidth = this.imgWidth * this.scale; var currHeight = this.imgHeight * this.scale; var correctX = (currWidth - this.imgWidth) / 2; var correctY

Get the upper, bottom, rightmost and leftmost point of a pixel-perfect BitmapData collision

给你一囗甜甜゛ 提交于 2019-12-13 18:11:02
问题 How can I get the upper, bottom, rightmost and leftmost point of a pixel-perfect BitmapData collision? This is my collision-detection code: public static function checkCollision(object1:*, object2:*, debug:Boolean = false):Boolean{ var object1Rect:Rectangle = object1.getRect(stage); var object2Rect:Rectangle = object2.getRect(stage); var object1Point:Point = new Point(object1Rect.x, object1Rect.y); var object2Point:Point = new Point(object2Rect.x, object2Rect.y); var bitmapData1:BitmapData =

Rotate 3D image batches to make them 2D

你。 提交于 2019-12-13 17:21:34
问题 My on_draw function is: def on_draw(self): self.clear() self.set3d() glPushMatrix() glRotatef(-rot[0], 1, 0, 0) glRotatef(-rot[1], 0, 1, 0) glTranslatef(-pos[0],-pos[1],-pos[2],) self.model.draw() glPopMatrix() pos (position) and rot (rotation) are lists of camera information used to transform the graphics. What I want to achieve is a doom-like effect where the images (certain parts of the scenery, players, enemy images) are kept so that they are parallel to the screen; they stay 2D,

Detect Marker Position in 2D image

孤街浪徒 提交于 2019-12-13 08:25:58
问题 I am using Java as programming language to fix a problem I am facing at the moment. I need to know the position (x,y) of the markers on the following image. Is that already been done with some java library I guess no? The markers are the little black squares. Thank you so much in advance for your help 回答1: I think chaper two of the book Mastering OpenCV with Practical Computer Vision Projects would be a good starting point. 来源: https://stackoverflow.com/questions/29746951/detect-marker

Finding 8 neighbours in 2d Array

别来无恙 提交于 2019-12-13 08:00:26
问题 I have looked around for this question, there are some answers about the question, but none that i really understand/or is not suitable for me. So my problem is to check for 8 neighbors in an 2d array containing chars, either * or O. Code: aliveCheck = isAlive(g,row,column-1); if(aliveCheck){ aliveCounter++; } aliveCheck = isAlive(g,row,column+1); if(aliveCheck == 1){ aliveCounter++; } aliveCheck = isAlive(g,row+1,column); if(aliveCheck == 1){ aliveCounter++; } Etc for all the 8 neighbours,