Tag Info

Hot answers tagged

14

Compute the vector representing the displacement between the two points p0 and p1: v = p1 - p0 and then compute the length of that vector: distance = sqrt(dot(v, v)) A vector in this case is an element of the real 3D coordinate space, so it has three components (X, Y and Z). A point also has the same three coordinates, and we can subtract two points ...


9

You will need to process all the points at least once so if this check is done only once there isn't much you can do to speed up the test other than brute-forcing it using parallelism. If the test is going to be run multiple times there are ways to pre-calculate tables to help, such as a grid of cells marked as [definitely inside (green in image), outside ...


7

What you are seeking is a solution to the "point-in-polygon" problem. It is described in Wikipedia here:           You can find C code following the links to Computational Geometry in C, or at many other locations found by searching for "point-in-polygon" code.


2

float rotation = 90f; while(true) { position = CircleRadius * new Vector2(Math.Cos(MathHelper.ToRadians(rotation)), Math.Sin(MathHelper.ToRadians(rotation))) + center; rotation += 1f; }


2

In your context, I think constant acceleration refers to acceleration's like Earth's gravity. This is lengthy because you are not specific about how you are using the model. Are you trying to simulate gravity, space travel, bullet riccochet, etc?? I'm kind of a math-nerd and would be happy to reply with more specific detail if you are more specific about ...


2

Turn the quaternion into a 3x3 matrix, transpose it (shortcut for the inverse of a purely rotational matrix), apply this matrix to your world space vector and you now have your model space velocity vector (entity's virtual axes: X=right, Y=Up, Z=forward or backward).


1

I think these two lines are not needed: Subtract(a,&entities[target].pos);// Make it relative to the obstacle model ... Subtract(b,&entities[target].pos);// Make it relative to the obstacle model I don't see why are you adding them. I think that if you remove them it should work as intended. EDIT: when you calculate the normal to the triangle ...


1

You can look into the Perspective n Point problem. I think that's what this issue is officially called.


1

public class Player { float rotation; Vector2 position; Vector2 center; float length; public Player() { position = new Vector2(Core.WIDTH / 2 - 10, Core.HEIGHT - 50 - 10); center = new Vector2(Core.WIDTH / 2, Core.HEIGHT / 2); rotation = 0; } public void turnRight() { rotation += 0.001; length = Math.sqrt(((position.x - center.x) * (position.x - ...


1

abs(x1-x2) + abs(y1-y2), as proposed by this answer will not always be correct. If you are willing to perform two more multiplication, you can perform an exact ordering without the cost of a squareroot. Consider the distances from (0,0) to the points (3, 4) and (5, 1). The distances are 5 and ~5.09, but the abs algorithm shows (5, 1) as being closer. ...


1

To calculate perspective projection divide by w. vec4 result = vec4(x, y, z, 1) * perspective_view_model_matrix; result /= w; You are then left with the (x,y) in screen space (-1 to 1). Multiply this by 1/2 screen width,height and you get pixel coordinates. You then need to take the corresponding vertex UVs, multiply by the texture size and you get ...


1

It's assumed that point A is at the origin. Let d be the unit vector in the direction point A is currently looking at, and p be the unit vector in the direction of B - A. Notice that d and p necessarily define a plane in 3D-space. If you can imagine this, then it becomes clear that a single rotation of d by an amount equal to the angle between these two ...


1

Have a look at this. It works through some very clear diagrams. http://www.mathopenref.com/coordpolygonarea2.html They are just calculating area and you are enumerating points. However you can adapt these ideas. Look carefully at 'A More Complex Case' and how the horizontal lines divide the polygon into a set of trapezoids (if you recognize a triangle as ...


1

You could possibly treat it as a graph traversal problem. If you treat adjacent points as 'children' of each other and add each child of your boundary points to a list of open nodes (ie. unvisited nodes), then your enumerator could explore this list. In case you're unfamiliar with search algorithms, this would probably look something like: For each point; ...


1

Every polygon can be represented as lines[L] with interception points[P].For each line you calculate weather it is above or below a point Pn(n is the index of array P) which is not part of the line Lm.When you measure all the lines you save the result in one dimensional bool array V[number_lines].When you have a random point A.Then you make for loop for ...



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