
Advertisement

Content count
7919 
Joined

Last visited

Days Won
1
Content Type
Profiles
Articles and Tutorials
News
Contractors
Columns
Podcasts
Games Industry Event Coverage
Gallery
Forums
Calendar
Blogs
Store
GameDev Links
Projects
Developers
Everything posted by alvaro

Separating components of a free form rotation
alvaro replied to OpaqueEncounter's topic in Math and Physics
I don't understand your "straightforward" plan . Try to explain very carefully what you are trying to do. The first word I don't understand in your description is "affect". I am not being pedantic: I honestly don't understand what you are trying to do, even if I substitute "effect" there. "Tweening" (I had to look it up) presumably refers to interpolation, but between what and what? If you expand the cross product, you'll see that your rotation vector is something very simple, like (delta.Y, delta.X, 0.0) or something like that. The way your code is written obscures what's going on. 
Those techniques are probably not worth it for a small game, but a small game could be a good test bed to get familiar with the techniques, so you can then use them in larger games. I would recommend reimplementing Snake in several different ways, to see what works and what doesn't. You will then be better prepared to make design decisions in more sophisticated projects.

Conversion from latlong to Cartesian coordinates 's result is different with real location
alvaro replied to nhungntc21's topic in Math and Physics
Those formulas are only valid if you are using a spherical model for Earth. Ellipsoid models do have some number called "N", but I haven't bothered to figure out the details. See this, for example: https://en.wikipedia.org/wiki/Reference_ellipsoid The OP hasn't posted enough detail for me to be inclined to help. 
Quickly finding location in an array that is similar to a smaller array.
alvaro replied to Syerjchep's topic in Math and Physics
Here's something that is much faster, although I don't know how applicable it is to your situation. Let's say you are looking for a pattern of K bits inside a long sequence of N bits. The naive algorithm to do this runs in time O(K*N), but you can do it in O(N*log(N)) using FFT, if you can reduce the problem to computing a convolution. If you are really interested in this possibility, let me know and I'll try to flesh out the idea, perhaps even with some sample code. 
Quickly finding location in an array that is similar to a smaller array.
alvaro replied to Syerjchep's topic in Math and Physics
First, it's a good idea to measure how much of the time is going to what operation. For instance, you seem to think that the pow is expensive, but how much faster is your algorithm if you remove it? Once you have a good idea of what the slow parts are, it's easier to think of optimizations. Here's another idea: Since the quality of each attempted match can be computed independently from all the others, you could program a GPU to run this algorithm. That could be a very big speed up. 
Quickly finding location in an array that is similar to a smaller array.
alvaro replied to Syerjchep's topic in Math and Physics
I just want to mention that pow(x, 8) will probably be computed as three multiplications, so it shouldn't be expensive. 
Approximating a 4variable function using regression.
alvaro replied to lucky6969b's topic in Math and Physics
Maybe because you ignored the correlations between the variables? Also, if you could post the full example it would be helpful. 
Get Angle of 3D Line and Rotate Polygon With Result
alvaro replied to Psychopathetica's topic in Math and Physics
I am having a hard time understanding what you are trying to do. I think part of the problem is that there are several notions that seem to be somewhat confused here: Angle: This is a single number that tells you how far apart the directions of two vectors are. Rotation: This is what is described with yaw, pitch and roll (or in many other ways). Direction: A class of vectors that are proportional to each other. If you are trying to align a polygon to another polygon, you need to find the normal directions to both polygons and then find a rotation that aligns one to the other. There are many such rotations, but there is a notion of "shortest rotation". But again, I am not sure what you are trying to do. 
I think you should probably make the selection of those parameters part of the level design. Have a human decide how to set all those variables in each level. You can even have thematic sections, perhaps indicated by the background and/or the music, where perhaps all the bricks have more hit points. In other sections perhaps they move faster... Just make sure that you have easy tools to tweak the experience of playing the game.

Although Albert is right that these things change over time, trigonometric functions are typically very expensive. So are hardtopredict branches, which perhaps is what's slowing down the first piece of code. It could also be that the drawing primitives are expensive, and you are making many more calls in your first piece of code than in your second piece of code. You could also start with a vector (1,0) and progressively rotate it. It would be like your second code but without most of the trigonometric function calls, or hardtopredict branches. One more thing: Why is the function that draws 8 symmetric points in the circle called `drawBresenhamCircle'? That's very confusing.

Printing % to a string? I need MANY % to get the percent symbol
alvaro replied to suliman's topic in For Beginners's Forum
After many years of using C++, the main reason I wouldn't go back to C is std::string. Next in the list of things I would miss are destructors that make sure things are cleaned up at the right time (a.k.a., RAII, or "resource acquisition is initialization", which is a name I never quite understood). Then come containers, like std::vector. The rest of the language I could probably do without. 
So you have two normals of adjacent convex polygons. Let's call the barycenters of the polygons A and B, and the corresponding normals vA and vB. Now compute n = cross_product(vA,vB). Now compute the [unsigned] angle between vA and vB and multiply the result by the sign of the determinant of the matrix whose columns are vA, vB and n. That's either the answer you want, or minus the answer you want. I can't be bother to figure out which, so just try it.

Here's the impression I got. Background first. The usual definition of angle in any dimension is the arccosine of the dot product of the normalized vectors. This is a number in [0,pi]. However, in 2D you can use something like atan2 to assign a sign to an angle, which is now a number in [pi,pi], where positive means conterclockwise and negative means clockwise. Since adding 2*pi to an angle doesn't change anything, you can think of the angle as being in [0,2*pi) if you want. This thread is about defining angles in 3D with the features of these 2D angles I just described. Unfortunately, there is no notion of clockwise in 3D in general. It is very likely that the OP has a picture in mind that is essentially 2D (e.g., a floor), and what needs to be done is project to a plane and use the 2D definition. "Clear as mud" is a very apt description of the information we are getting from him/her. As is often the case in the Math forum, if you could express your question in correct and precise language, you probably would't need help figuring out the answer, so we should give people a little slack.

Truly understanding linear algebra will help enormously as a base for all of these subjects. A university course is probably the best way to get there, complemented with "Essence of linear algebra": https://www.youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab On the wavelet transform (or wavelets more generally): https://www.amazon.com/WaveletTourSignalProcessingThird/dp/0123743702 https://www.amazon.com/LecturesWaveletsCBMSNSFConferenceMathematics/dp/0898712742 Also, search the web and you'll find threads on other forums where people have asked these things: https://mathoverflow.net/questions/4835/introductiontowavelets For AI, https://www.amazon.com/ArtificialIntelligenceModernApproach3rd/dp/0136042597 On data structures (including binary trees), I liked the "Algorithms in <language>" books by Sedgewick, which I guess evolved into this: https://algs4.cs.princeton.edu/home/ . And of course you could read Knuth's "The art of computer programming", if you have nothing to do the next 10 years. For spherical harmonics I don't have a good recommendation, other than to first get very familiar with Fourier series and with orthogonal families of functions in general. Then you can just search the web and read just about any description, and it will make sense.

Printing % to a string? I need MANY % to get the percent symbol
alvaro replied to suliman's topic in For Beginners's Forum
You should never use sprintf to begin with, because it has no way of checking if you are writing past the end of the buffer. A valid alternative is snprintf. Then again, you should only use this when you need formatting. When passing the string around, when storing it or when sending it to the drawing function, you should just handle it as a plain string, without doing any formatting. EDIT: Oh, and please use std::string if you are programming in C++. You are much less likely to mess up that way. 
Say I am looking at you face to face and I hold up a transparent sheet of plastic with the picture of two vectors on it, v1 and v2. If I measure the clockwise angle between v1 and v, I'll get a different answer than if you measure it. You need to specify from which direction you are looking at the vectors. That's where the vector n comes in. The notion of the orientation of two vectors is not well defined in 3D, so any solution you find is bound to have issues. What exactly are you trying to do?

Marching Cubes and Dual Contouring Tutorial
alvaro replied to Boris The Brave's topic in Math and Physics
Actually, for any finite number of iterations, the set of points for which a divergence has not been found has a differentiable boundary. Those pictures are pretty! 
Just concentrate on learning one of the things, implement it yourself, try to use it to solve some problems. Then move on to the next one. You can try to make the bigpicture connections between things once you are an expert.

The wavelet transform is a mathematical operation, AI is a field of study and binary tree is a data structure. The interesting question is not what the difference is between them, but whether they have anything in common...

Marching Cubes and Dual Contouring Tutorial
alvaro replied to Boris The Brave's topic in Math and Physics
Fractals are not differentiable, so the normal is not defined. No wonder you are having a hard time computing it. 
Marching Cubes and Dual Contouring Tutorial
alvaro replied to Boris The Brave's topic in Math and Physics
The link to the 3D tutorial from the 2D tutorial is broken: http://www.boristhebrave.com/2018/04/08/marchingcubes3dtutorial/ should be http://www.boristhebrave.com/2018/04/15/marchingcubestutorial/ Also, I think marching triangles and tetrahedra should be mentioned. They are an attractive alternative because the number of cases is much smaller. 
max number of triangles and edges in Delaunay triangulation
alvaro replied to lawnjelly's topic in Math and Physics
In case anyone is interested in a proof, here it is. If n is the number of vertices and b is the number of vertices on the boundary of the convex hull of all the points, we can add up the inner angles of all the triangles in two different ways. The angles formed around an interior point add up to 2*pi. The angles formed around a point on the boundary of the convex hull add up to pi minus a little bit. Those little bits add up to 2*pi, as you go around the convex hull once. The other way of counting it is pi * number of triangles. So we get pi*number of triangles = 2*pi*(n  b) + pi*b  2*pi Dividing by pi, number of triangles = 2*n  b  2 The minimum value for b is 3, so the maximum number of triangles is 2*n  5 For the number of edges, you can use 3 * number of triangles, but most edges would have been counted twice. The edges that are not counted twice are the ones on the boundary of the convex hull, so there are b of them. You can then count the number of edges, like this: number of edges = (3 * number of triangles + b) / 2 = (6*n  3*b  6 + b) / 2 = 3*n  b  3 As before, the minimum value for b is 3, so the maximum number of edges is 3*n  6 
max number of triangles and edges in Delaunay triangulation
alvaro replied to lawnjelly's topic in Math and Physics
maximum number of triangles = 2 * number of vertices  5 maximum number of edges = 3 * number of vertices  6 
max number of triangles and edges in Delaunay triangulation
alvaro replied to lawnjelly's topic in Math and Physics
[EDIT: Answered too fast. Let me think about it a bit more. Sorry!] 
the order of three orthonormal vectors in rotation matrix
alvaro replied to flyingsalmon's topic in Math and Physics
If your rotation is the identity (i.e., "don't rotate"), you need to use the identity matrix. If you read the columns of the identity matrix, you'll get (1,0,0), (0,1,0), (0,0,1). So x, y, z.

Advertisement