Tag Info

Hot answers tagged

49

A perfectly straight line would also be the shortest possible line with a total length of sqrt((x1-x2)² + (y1-y2)²). A more scribbly line will be a less ideal connection and thus be inevitably longer. When you take all individual points of the path the user drew and sum up the distances between them, you can compare the total length with the ideal length. ...


27

This might not be the best way to implement this either, but I suggest a RMSD (root mean square deviation) could be better, than merely the distance method, in cases mentioned by Dancrumb (see first two lines below). RMSD = sqrt(mean(deviation^2)) Note: The sum of the absolute deviations (integral-like) might be better, as it does not average out ...


19

Existing answers do not take into account that the end points are arbitrary (rather than given). Thus, when measuring the straightness of the curve, it does not make sense to use the end points (for example, to calculate expected length, angle, position). A simple example would be a straight line with both ends kincked. If we measure using the distance from ...


3

A* operates fundamentally on a graph, not a grid. When you create a grid for A* to search, what you've actually done is created something called a "lattice graph." The connections between nodes in the lattice can be anything. They don't have to just be straight lines between neighboring grid cells. In your case, you can combine the best of both worlds just ...


2

This is a grid based system, right? Find your own points for the line and calculate the slope of the line. Now, using that calculation, determine valid points that the line would pass through, given some margin of error off the exact value. Through a short amount of trial-and-error testing, determine what good and bad amount of matching points would exist ...


2

The idea is to keep all the points the user touched, then evaluate and sum the distance between each of those points to the line formed when the user releases the screen. Here is something to get you started in pseudo-code: bool mIsRecording = false; point[] mTouchedPoints = new point[]; function onTouch mIsRecording = true functon update if ...


2

I'd like to chime in and mention "format preserving encryption" as a method for shuffling cards in a game. Essentially what you'd have is an encryption algorithm that takes in a value 0 to 51, and a key (shuffle seed) and spits out a value 0 to 51. Since encryption is reversible by definition that means any 2 input numbers cannot encrypt to the same output ...


2

One method you could use is to subdivide the line into segments and do a vector dot product between each vector that represents the segment and a vector representing a straight line between the first and last point. This has the benefit of letting you find extremely "spiky" segments easily. Edit: Also, I would consider using the length of the segment in ...


2

A very easy and intuitive measure is the area between the best fitting straight line and the actual curve. Determining this is fairly straightforward: Use a least-squares fit on all points (this prevents the end-kink problem mentioned by Joel Bosveld). For all points on the curve, determine the distance to the line. This is also a standard problem. (linear ...


1

(A place to start that's easier than comments:) Maintain a list of tiles that need calculating; the initial list contains only the city-tiles. Each city-tile generates influence, X, and adds it to each of its' 8 nearest neighbors, also adding each neighbor to the list. (Does the city pass only 1/8 of its influence to each?) The city-tile then removes ...


1

If you have multiple sprites at the same position, are they all supposed to prevent the player from falling? if so, you can either merge them, or disable collision for one. Else, if not all the sprites should collide, maybe you can add a flag to indicate if they are ground colliders. On a side note, you could use a complete AABB instead of using arbitrary ...


1

The easiest and quickest might be simply to find out how thick the line would have to be to cover all the points of the user drawn line. The thicker the line has to be, the worse the user did in drawing their line.



Only top voted, non community-wiki answers of a minimum length are eligible