2d

Determining ordering of vertices to form a quadrilateral

点点圈 提交于 2019-12-03 09:12:17
Suppose I have 4 vertices in 2D space. Does anything know of an efficient algorithm which will give me an ordering of the vertices which corresponds to a simple quadrilateral? That is, it will label the vertices 1, 2, 3, 4 so that if I follow 1-2, 2-3, 3-4 I will have traced a simple (i.e. non-intersecting) quadrilateral. Just providing the name of a standard algorithm which I can google would be fine. You may be interested in methods of convex hull computing, such as Graham scan . If your shape is convex, you can go in winding order around the barycentre of your points (i.e. the centre of

Creating 2D bins in R

廉价感情. 提交于 2019-12-03 09:03:35
I have coordinate data in R, and I would like to determine a distribution of where my points lie. The entire space of points is a square of side length 100. I'd like to assign points to different segments on the square, for example rounded to the nearest 5. I've seen examples using cut and findinterval but i'm not sure how to use this when creating a 2d bin. Actually, what I want to be able to do is smooth the distribution so there are not huge jumps in between neighboring regions of the grid. For example (this is just meant to illustrate the problem): set.seed(1) x <- runif(2000, 0, 100) y <-

Java collision detection between two Shape objects?

自古美人都是妖i 提交于 2019-12-03 09:03:18
问题 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 the intersects() method in the Shape class can only take a Rectangle or a Point as a parameter, not another Shape. Is there an efficient way to test if two Shape objects are overlapping in any way? One way I tried was using a for loop to generate an

C++ library for drawing graphics [closed]

送分小仙女□ 提交于 2019-12-03 08:51:18
问题 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 2 years ago . Someone can suggest me a good, free, easy to use library for c++ that allow to draw a mathematical function in a window for microsoft windows? (e.g. the parabola x^2+5x+3=0) 回答1: Another wxWidgets-based option is wxArt2D, It has got tons of good features for drawing mathematical functions as curves, like you

Algorithm to divide a chocolate bar in equal parts

空扰寡人 提交于 2019-12-03 08:20:08
问题 A random thought popped into my head (when I was sharing a chocolate bar of course!). I was wondering if there is a generic algorithm to solve this problem. The problem goes like this: Info 1. You have a chocolate bar with small squares arranged in a rectangular matrix 2. There are n people in the room The problem Write an algorithm that outputs the optimal configuration (p x q) where the bar can be shared equally between n, n-1, n-2...., 2, 1 people given the following restrictions: 1. A

Fast way to implement 2D convolution in C

大城市里の小女人 提交于 2019-12-03 07:57:11
I am trying to implement a vision algorithm, which includes a prefiltering stage with a 9x9 Laplacian-of-Gaussian filter. Can you point to a document which explains fast filter implementations briefly? I think I should make use of FFT for most efficient filtering. Are you sure you want to use FFT? That will be a whole-array transform, which will be expensive. If you've already decided on a 9x9 convolution filter, you don't need any FFT. Generally, the cheapest way to do convolution in C is to set up a loop that moves a pointer over the array, summing the convolved values at each point and

Rotate rectangle around a point

烂漫一生 提交于 2019-12-03 07:40:01
How would I get 4 points rotated a certain degrees around a pointer to form a rectangle? I can rotate a point around a point, but I can't offset it to make a rectangle that isn't distorted. If you can rotate a point around a point then it should be easy to rotate a rectangle - you just rotate 4 points. Here is a js function to rotate a point around an origin: function rotate_point(pointX, pointY, originX, originY, angle) { angle = angle * Math.PI / 180.0; return { x: Math.cos(angle) * (pointX-originX) - Math.sin(angle) * (pointY-originY) + originX, y: Math.sin(angle) * (pointX-originX) + Math

HTML5 - Creating a viewport for canvas

蹲街弑〆低调 提交于 2019-12-03 07:33:34
问题 I have a 2D array that is 30 across, 20 down. However, the viewport only paints 15 across and 10 down. I had a game like that originally and I've been trying to achieve something like this: Here's my fiddle: http://jsfiddle.net/sTr7q/ 回答1: Here I've made a rudimentary viewport for you: http://jsfiddle.net/kmHZt/ You have to keep track of the viewport X and Y (vX, vY) that represent where you are in the world at large. I also kept the viewport width and height as vars instead of hard coding

Setting up a 2D view in Three.js

老子叫甜甜 提交于 2019-12-03 07:28:13
问题 I'm new to three.js and am trying to set up what amounts to a 2D visualization (for an assortment of layered sprites) using these 3D tools. I'd like some guidance on the PerspectiveCamera() arguments and camera.position.set() arguments. I already have a nudge in the right direction from this answer to a related question, which said to set the z coordinate equal to 0 in camera.position.set(x,y,z) . Below is the snippet of code I'm modifying from one of stemkoski's three.js examples. The parts

HTML5 Tile Engine

最后都变了- 提交于 2019-12-03 07:20:53
问题 Where can I find a tile engine for HTML5 <canvas> , for writing 2D games? 回答1: Possibly: http://www.effectgames.com/effect/ and in particular http://www.effectgames.com/effect/#Article/docs/Sprites_and_Tiles_Guide However note that effect is free to use but proprietary and not open source. Other Javascript/Canvas game engine libraries that would make it easy (but may not have specific tile support/documentation): http://github.com/kesiev/akihabara http://gamejs.org/ http://code.google.com/p