2d

Collision detection in a 2D maze with thick walls

岁酱吖の 提交于 2019-12-10 07:27:40
问题 I have to make a game with Windows Forms for school. My game consists of a user having to get through a maze. I'm trying to prevent my user from going straight through the walls using collision detection, but am getting stuck because of the varying shape of the rectangles being used to represent walls. Here's an image of the game. This question may be similar to this one, however with my movement I believe that it is quite different, as I don't have a grid system or graphical map laid out. As

Cross product of 2 2D vectors

拥有回忆 提交于 2019-12-10 03:54:08
问题 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;

Footprint finding algorithm

社会主义新天地 提交于 2019-12-10 03:34:28
问题 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.

Distance between elements in 2D array

一曲冷凌霜 提交于 2019-12-09 18:21:34
问题 How can I determine the distance between 1's in a 2D array. For example, we have a 2D array like this: 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 The algorithm has to output the distance from each element to the nearest 1. Like this: 2 3 2 1 1 2 1 0 0 1 2 1 0 1 2 2 How can I solve it ? 回答1: You can iterate over the matrix and find the coordinates of all the 1's (x1, y1). Then for each position in the cell (x2, y2), for all (x1, y1) in your list, find the minimum |x2 - x1| + |y2 - y1| (the Manhattan

How to create a curve between 2 points in 2D and get back Points that makes that curve every d distance?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 17:51:50
问题 I'm not good in math. I have 2 points, A(x1, y1) and B(x2, y2) in 2D. I need to create a virtual path from point A to B curved at R(radius), and then return an array of points which are describing this curved path, not all maybe every D(distance) from each other. In Java I need a method like this: private ArrayList<PointF> generateCurve(PointF pFrom,PointF pTo,float pRadius,float pMinDistance){ ArrayList<PointF> pOutPut = new ArrayList<PointF>(); // ...generate result to pOutPut return

Scala - Easiest 2D graphics for simply writing a 2D array to the screen? [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 16:52:14
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . What do you recommend for writing a 2D array of pixels to the screen? My first thought is some SWT binding, but are there any others? Processing perhaps? 回答1: It's not too hard in Swing - you can cut and paste the below. You could simplify it a bit if you don't want colours or the ability to draw to any size

Data Structure for Spatial Agent Based Modeling [closed]

天涯浪子 提交于 2019-12-09 11:49:52
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . 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

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

99封情书 提交于 2019-12-09 10:38:50
问题 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

Area covered by a point cloud with R

自古美人都是妖i 提交于 2019-12-09 09:52:05
问题 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 回答1: 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

How can I convert 3D space coordinates to 2D space coordinates?

江枫思渺然 提交于 2019-12-09 09:23:40
问题 I'm using a Lua API. I'm trying to transform 3D space coordinates to 2D space coordinates. I've asked google but I can't find anything apart from snippets using OpenGL function. I don't need source code or anything just a simple way on how to do it? I can acquire the Camera's perspective, the original position to be transformed, window size and aspect ratio if that's any help? Thanks in advance for any suggestions :) 回答1: If you're talking about transforming world-space (x,y,z) coordinates to