Questions tagged [2d]

2D computer graphics is the computer-based generation of digital images—mostly from two-dimensional models.

Flat perspective, having no three-dimensional geometry. Including two-dimensional space and 2D geometric models, or two-dimensional images having only height, and width with no depth.

7489 questions
18
votes
4 answers

Java collision detection between two Shape objects?

I would like to know the best way to tell if a Shape object intersects another shape. Currently I have collision detection in my game sorted out as long as it involves a Shape intersecting a Rectangle or vice versa. The problem I'm having is that…
Monkeybro10
  • 267
  • 1
  • 4
  • 8
18
votes
8 answers

Allocate memory 2d array in function C

How to allocate dynamic memory for 2d array in function ? I tried this way: int main() { int m=4,n=3; int** arr; allocate_mem(&arr,n,m); } void allocate_mem(int*** arr,int n, int m) { *arr=(int**)malloc(n*sizeof(int*)); for(int…
serhii
  • 1,135
  • 2
  • 12
  • 29
18
votes
5 answers

Detect if a set of points in an array that are the vertices of a complex polygon were defined in a clockwise or counterclockwise order?

EDIT: I updated the program with the answer and it works great! I am making a program (feel free to try it out) that lets users draw polygons which it then triangulates. They can click to add vertices and hit enter to triangulate. Anyways, the…
Conner Ruhl
  • 1,693
  • 4
  • 20
  • 31
17
votes
3 answers

Drawing rectangle between two points with arbitrary width

I'm trying to draw a line between two (2D) points when the user swipes their finger across a touch screen. To do this, I plan on drawing a rectangle on every touch update between the X and Y of the previous touch update and the X and Y of the latest…
AaronDS
  • 851
  • 2
  • 13
  • 31
17
votes
5 answers

Place random non-overlapping rectangles on a panel

I've a panel of size X by Y. I want to place up to N rectangles, sized randomly, upon this panel, but I don't want any of them to overlap. I need to know the X, Y positions for these rectangles. Algorithm, anyone? Edit: All the N rectangles are…
Scott Evernden
  • 39,136
  • 15
  • 78
  • 84
17
votes
6 answers

How to draw a dashed line over an object?

I am drawing a line on a control on my Windows form like this: // Get Graphics object from chart Graphics graph = e.ChartGraphics.Graphics; PointF point1 = PointF.Empty; PointF point2 =…
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
17
votes
4 answers

Simple 2d polygon triangulation

Trying to triangulate a set of simple 2d polygons, I've come up with this algorithm: 1) For each vertex in the polygon, compute the angle between the two linked edges 2) Sort vertices by decreasing angle relative to the interior of the polygon 3)…
Nicolas Repiquet
  • 9,097
  • 2
  • 31
  • 53
17
votes
3 answers

Area of self-intersecting polygon

Calculating the area of a simple irregular polygon is trivial. However, consider the self-intersecting polygon ABCDEF shown at left below:                     If we use the linked-to formula above traversing the points in polygon order, we get an…
Phrogz
  • 296,393
  • 112
  • 651
  • 745
16
votes
1 answer

Changing From Perspective to Orthographic Matrix

I have the scene with one simple triangle. And i am using perspective projection. I have my MVP matrix set up (with the help of GLM) like this: glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f); glm::mat4 View =…
IanDess
  • 657
  • 2
  • 11
  • 26
16
votes
11 answers

Mathematics and Game Programming

I want to program graphical 2D games more complex than the basic 2D stuff I already know. I don't want to do 3D programming. Just more complex 2D stuff. I dropped high school before I could learn a lot of stuff so I walked away with enough algebra…
Xfcn
  • 171
  • 1
  • 1
  • 4
16
votes
1 answer

Sprite and animation making tool for android game

I am new at Android game development. I want to know how can i create and Animate the game characters i have in mind. Is there a tool out there that can help me get started with the drawing or i have to draw frame-by-frame. I am targeting simple 2D…
16
votes
4 answers

3d to 2d Projection Matrix

I have 3 points in a 3D space of which I know the exact locations. Suppose they are: (x0,y0,z0), (x1,y1,z1) and (x2,y2,z2). Also I have a camera that is looking at these 3 points and I know the 2D locations of those three points on camera view…
ehsan baghaki
16
votes
2 answers

Curvilinear perspective: Convert 3D to 2D

I'm looking for the mathematical expression converting a 3D coordinate (x0,y0,z0) to a 2D (x1,y1) coordinate in a curvilinear perspective of radius R where the values of x1 and y1 are the angles of views {-90° .. +90°} of the original…
Pierre
  • 34,472
  • 31
  • 113
  • 192
16
votes
4 answers

Bezier clipping

I'm trying to find/make an algorithm to compute the intersection (a new filled object) of two arbitrary filled 2D objects. The objects are defined using either lines or cubic beziers and may have holes or self-intersect. I'm aware of several…
jjrv
  • 4,211
  • 2
  • 40
  • 54
16
votes
1 answer

Movement from 2D to 3D

Can anyone give me some advice or suggestions I need to find how much an object in a photograph has move from one position to another (well actually I need to calculate how much the camera has moved between 2 images but as the object will remain…
heyred
  • 2,031
  • 8
  • 44
  • 89