Tag Info

Hot answers tagged

26

You're trying to calculate the Torque. Torque depends on the applied force F, the point of application, and the center of mass of the object. 1) Center of Mass. Define the center of mass of the object. 2) Point of Application: Define the point at which the force acts on. 3) Moment Arm: The distance between the two points defined above. Point ...


23

What are vectors? Vectors are sets of coordinates of varying dimension. Each coordinate in a vector represents some absolute position in that direction of the space the vector is in. A 1-D vector would be {1} . This could be, for example, a position at X = 1. Or a time t = 1. A 2-D vector would be {-4,3}. This could be, for example, a position at -4 on ...


16

Compute a vector V from A to B, and normalize it. V = (B - A) / |B - A| Since the vector is normalized, it will have a length of one, and it will indicate the direction of B relative to A. If you then scale the vector by d you will have the displacement from A to C V' = d * V which you can simply add to A to yield C: C = V' + A


15

It sounds like you want to keep the speed of the object at some constant value over the entire curve - knowing the arc-length won't help you do this. It will help you calculate at what time the object would reach its end-point if it were going at that speed, so it will be better than what you have now (the object will have the same average speed between all ...


14

It's much faster to use a 2d cross-product. No costly trig function involved. b2Vec2 target( ... ); b2Vec2 heading( ... ); float cross = b2Cross( target, heading ); if( cross == -0.0f ) // turn around if( cross == 0.0f ) // already traveling the right direction if( cross < 0.0f) // turn left if( cross > 0.0f) // turn right If you ...


13

A 2D example are screen coordinates, it identifies a pixel on the screen and has an x- and an y-component [x, y] i.e. Left upper screen position [0, 0] Another example: Imagine a text scrolling from right screen border to the left screen border. Now you need to define the velocity of the scrolling text in pixel per second, i.e. [-20, 0] which means the text ...


13

LERP - Linear Interpolation I gave this answer for a similar problem some days ago, but here we go: Linear Interpolation is a function that gives you a number between two numbers, based on the progress. You could actually, get a point between two points. The Great Formula - How to calculate it The general LERP Formula is given by pu = p0 + (p1 - p0) * ...


13

The angle you need to rotate by is the the angle your velocity vector makes with the positive x-axis. This angle can be calculated using the inverse tan of the slope of the vector. In XNA, we use the Math.Atan2 function. Give the function the y coordinate and the x coordinate of the velocity vector (in that order). Atan2 will return an angle between +PI/2 ...


13

Is there any notable performance between Vector2s and Vector3s, for example when adding or multiplying them, or when calling Normalize, Transform, or Distance? Yes, you have one more coordinate so you will use more CPU cycles. But it is very unlikely that it will ever give you any trouble. XNA 4 is using SIMD extensions for vector math (EDIT: on ...


11

You seem to be trying to implement the Painters Algorithm. I'm guessing you're trying to write a rasteriser from scratch as a learning exercise, as most modern 3D hardware uses what Bart has mentioned (the Z/Depth buffer). For the painters algorithm to work in all cases, you'd need to be prepared to subdivide the surfaces as they're rendered to solve ...


11

From MathWorld: Given the plane Then the normal vector is The normal unit vector n is given by: Therefore, for the plane 5x+2y+3z-1=0, The normal vector N is N = [5,2,3] The magnitude |N| is |N| = sqrt(5^2 + 2^2 + 3^2) |N| = 6.1644 The normal unit vector n is therefore approximately: n = N / |N| n = [0.8111, 0.3244, ...


11

You are looking for the wondrous atan2. // v1 moving object float boxX = this.mScene.getLastChild().getX(); float boxY = this.mScene.getLastChild().getY(); // v2 user touch float touchX = pSceneTouchEvent.getX(); float touchY = pSceneTouchEvent.getY(); double theta = 180.0 / Math.PI * Math.atan2(boxX - touchX, touchY - boxY); Normally it is used ...


10

This is a simple operation of vector difference. In XNA you don't even need to create a specific method for it - vectors already support subtraction. If you want the velocity of Body B from the perspective of Body A, you subtract Body A's velocity from Body B. So in C# with XNA, using your example: Vector2 MovingBody = new Vector2(1, 0); Vector2 Impact = ...


10

The simplest way is probably to get the angle of the vector using atan2(), as Tetrad suggests in the comments, and then scale and round it, e.g. (pseudocode): // enumerated counterclockwise, starting from east = 0: enum compassDir { E = 0, NE = 1, N = 2, NW = 3, W = 4, SW = 5, S = 6, SE = 7 }; // for string conversion, if you can't just do ...


9

If I understand your problem properly, you should just have a direction Vector2 representing the direction you want to move in inside your sprite class. Like this: public Vector2 Direction { get; set; } This is the normalized vector(which means it has a length of 1) showing where you want to go. Then, add a Speed float property, which says how fast the ...


9

Use arcsin of the 2D cross product (i.e the z component of the cross product vector). That'll give you -90 to 90 which will let you know whether to go left or right. Be careful because A cross B is not the same as B cross A. Another strategy (but probably not as straight forward) is to calculate the "heading" of the two vectors using atan2 and then ...


9

There are a few things to consider here. The first is that a face is not necessarily rotated just because its normal is not aligned with an axis. The second is that you can't obtain Euler angles (x,y,z rotations) from just a normal. You would need to know at least 2 non collinear vectors to do that as you need three perpendicular vectors (a basis in R3) to ...


9

The native Vector2 class doesn't seem to have half of this stuff, but it is used in a lot of places. The Vector3 has all this stuff, but has an extra dimension I don't need. I believe you're mistaken; Vector2 and Vector3 both have extensive functionality. Note that this functionality is exposed as static methods to the Vector2/Vector3 class, rather than ...


9

Think about the problem differently. You want to object always to "face" the player, which means you want its "forward" vector rotated around to be parallel to the vector from itself to the player. Assuming its "forward" vector is normally at obj.Rotation = 0, the proper rotation is basically the arctangent of Vector2.Subtract(playerPos, objectPos). Most ...


9

My answer to this question would be the same as my answer to this other question: When should vector/list be used? Basically, cache-coherency-related performance gains from having everything be contiguous in memory is more valuable than "Big O" algorithm theoretical performance from linked lists.


9

Blue vector can be calculated easily: red - black (the sign between vectors is minus). But if you want just to interpolate between black and red vector, you don't have to calculate it. Linear interpolation is just linear combination. So you can just take: alpha * black + (1 - alpha) * red, where alpha has to be from interval <0,1>. If alpha will be 1, ...


9

I think you should not try to hardcode this behavior as a series of if-elses like you're doing, because this will make it very difficult to extend or change if you need different values, or to add more positions in the path. Instead look into adding the capability of following any path to your entity. Here's an example (I'll give the example in 2D but it ...


9

Given only a point and a direction there is no defined 'right' or 'left'. Imagine being a falling raindrop, which direction is right or left for you in that case? In order to calculate (or even define) a right or left you need two directions, typically forward and up. You seem to already have a forward direction, so you need to define a up direction. ...


8

Just multiply the vector by a rotation matrix: | fx | | cos a -sin a | | sx | | fy | = | sin a -cos a | | sy | where fx and fy are final coordinates of the object after the rotation and sx, sy are starting one. Obviously a is the angle involved.


8

What you want to do can also be thought of as reflecting the particle's velocity off the plane tangent to the circle at the point of contact. If you know the equation for doing that, then all you need to know is the circle's normal at the point of contact. To get that, all you need to do is normalize the vector from the center of the circle to the point in ...


8

It's unlikely there would be any problems with conflating the definitions and treating points as vectors — but be a little careful, because some APIs have a 'Point' class that you might need to use (for representing, e.g., vertices of polygons) and if you define your own class you'll want to be able to port them back and forth. What I would do, ...


8

Let's first discuss the dot product. A·B is a measure of A's component in the direction of B or vice versa; of the magnitudes of both vectors as well as their similarity in direction. Vectors pointing in the same direction have a dot product equal to the product of their lengths, perpendicular vectors have a dot product of zero. Turn the vectors even ...


8

You have 8 options (or 16 or more if you want even finer precision). Use atan2(y,x) to get the angle for your vector. atan2() works in the following way: So x=1, y=0 will result in 0, and it's discontinuous at x=-1, y=0, containing both π and -π. Now we just need to map the output of atan2() to match that of the compass we have above. Likely the ...


7

Of course there is. Compute the determinant of the orientation vector of the runways and the vector from one runway centre to another, the result will be positive or negative depending on which runway are to the right of the other. Calculation of determinant for a pair of 2D vectors: Det(A,B) = Ax*By - Ay*Bx There is a load of other stuff one can learn ...


7

I fear the subject is quite tricky, few multi platform solutions seem to have launched, and even fewer seem to have survived on their own. I was looking into the subject a few months ago. I had a constraint as I needed the engine to run on iOS and Android. Didn't find anything that suited me really at the time. But a few pointers from what I remember: each ...



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