Tag Info

Hot answers tagged

11

As your feared, you are oversimplifying. If you transform your scene so that the ellipse becomes a circle, you are using a non-isometric transformation and relative distance is not preserved. This can be best seen in the following diagram, where the point closest to the black point clearly changes: Finding the closest point on an ellipse is a non-trivial ...


8

Let C₁ and C₂ be the sphere centres, and R₁ and R₂ their radiuses. We pick a point A on the intersection circle and we want to find B, the centre of the intersection circle: Pythagoras gives us the following two equalities: AB² = AC₁² - BC₁² AB² = AC₂² - BC₂² Combining the two and replacing AC₁ with R₁ and AC₂ with R₂: BC₁² - BC₂² = R₁² - R₂² We ...


6

How do you store the ellipsoid? If it has a position, orientation and the radius in local x- and y-axis, it might be easier to calculate the inverse transformation matrix, that transforms the ellipsoid to a circle. Transform the AABB into that space too using that matrix, then you can make simple triangle-circle collision tests. Edit: In the left image ...


5

While Zhen's example code is perfectly fine, I'd use one big expression (might not be possible based on your actual language): bool pointInRectangle(Rectangle rect, Point point) { return p.x >= r.x && // point is right of the left edge p.y >= r.y && // point is below the top edge p.x <= r.x + r.w && ...


5

Given two parametric equations of lines; L=a+t.b // t is the paramerter, a & b are vectors M=c+u.d //u is parameter, c & d are vectors The the point of intersection is the one place in space where both these equations are equal(produce the same point). When the lines intersect at some value of t and some value of u, the equations are equal, ...


5

Try the following method which relies on XNA's built in Math API to intersect a Ray and a Plane and get back the point of intersection: Vector3? GetRayPlaneIntersectionPoint(Ray ray, Plane plane) { float? distance = ray.Intersects(plane); return distance.HasValue ? ray.Position + ray.Direction * distance.Value : null; } The method returns null if ...


4

The Sutherland-Hodgman polygon clipping algorithm should work just fine for triangle vs. rectangle clipping. You'll find some more information about clipping algorithms here. Or just search for "Sutherland Hodgman clipping".


4

Calculate the three corners of your fov triangle, rotate them to be facing the correct way and such, and then do one of: 1) do a point-in-triangle test for all the potential targets 2) calculate the bounding box of the this triangle, and do a point-in-triangle test for all potential targets in cells in this bounding box - this will be very straightforward ...


3

I don't know what's the problem with your implementation, but I have used the method below (taken directly from this sample) on a raytracer and it worked correctly and performed well too. So you might consider swapping to this implementation: /// <summary> /// Checks whether a ray intersects a triangle. This uses the algorithm /// developed by Tomas ...


3

Your code seems to use quads and it seems that you don't use the two triangles from the quad but two overlapping ones (say the second one is wrong), try this instead (see the "v2, v3, v0" part) : if(rayTriangleIntersect(rayOrigin, rayDirection, v0, v1, v2, ref intersectPosition) || rayTriangleIntersect(rayOrigin, rayDirection, v2, v3, ...


3

It's easier to think of this using vector maths. The plane equation is N.P = -D for all points on the plane. Therefore, the intersection point must satisfy this. If our point P is defined by the line equation P = P0 + tQ (where Q is the line's direction and t is the distance along the line) we can sub this in: N.(P0 + tQ) = -D The dot product is ...


3

linear systems of N variables can be solved if you have N equations. x = 10ɑ y = 20ɑ z = -10 + 40ɑ x = β y = 2β + μ z = 0 6 equations, 6 unknowns. You can solve for all 6. In fact, generally you can just combine the x/y/z parts and say 10ɑ = β 20ɑ = 2β + μ -10 + 40ɑ = 0 and get 3-variable system in ɑ,β,μ. Once you get a value for ɑ, you can plug back ...


3

The canonical solution in software renderers (which must do this exact algorithm every time they rasterize a triangle) is, I believe, to scan the triangle one row of pixels at a time. The left and right edges of each row and calculated by walking down the sides of the triangle using Bresenham, and then you fill in the row between them. I'm glossing over ...


3

In general, lines are a poor approximation of a user's movement because they don't account for the size of the player. You want "sweep sphere triangle intersection", also called "capsule triangle intersection". http://xania.org/Games has a good overview of this.


2

If cube is axis-aligned, then it's easy. You can compare each vertex of triangle with each face (plane) of cube. If it's out of cube (just compare apropriate coordinates), then find two new points, which lie on line connecting two other vertices with that one out of cube and which lie on plane (their coordinate is same as the plane). This is common linear ...


2

I don't know about Flash technology, nor how the game is updated. Presuming that there can be an Update() method like the one encountered in XNA that is called from within the game loop, would it not be possible to simply calculate: the coordinates of your enemy's center, that is, (x2, y2) based on its current location; than the coordinates of the ...


2

I'm using a variation of the scanline algorithm to solve the exact same problem. I started by sorting the three triangle points by their height. I then basically check whether two edges are on the left or on the right side. For the side with two edges, you have to mark they row where you change which edge delimits your rows. For the side with one edge, you ...


2

It's not very clearly explained in the paper, but you can tell which two out of the three edges to look at by seeing which vertices are on which side of the other triangle's plane. For instance, if triangle 1's vertices are A, B, C, and A and B are on one side of triangle 2's plane and C is on the other side of triangle 2's plane, then AC and BC are the ...


2

Xna's Ray.Intersect() tests that utilize the Ray's direction assumes that the direction vector is unit length. If you normalize ray.Direction before running the test you will find it will not intersect. the documentation supports the direction vector being unit length.: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.ray_members.aspx Unit ...


2

It's generally both easier and faster to convert rays into the object's local space and do the test. It's either 1 tranformation on the ray or N transformations of N vertices into world space, and for even a single triangle 1 will be less than N. For objects like OBBs it's also much easier to just treat it like an AABB in object space when doing ray ...


2

Let's see if I can clarify the maths a bit. You have two lines: Line r1 such that some point p1 = a + L*b where a is a position vector and b is the direction and L is a parameter. Line r2 such that some point p2 = c + M*d where c is a position vector and d is the direction and M is a parameter. Each line has its own parameter. You want to find where ...


2

If you want to spawn particles on the surface of a mesh, it's relatively easy: pick a random triangle, then pick a random point on it. The choice of triangle should be weighted by area so that the particles don't clump into the denser areas of the mesh (unless that is a desirable effect). To spawn particles within the volume enclosed by a mesh is harder. ...


2

As the link suggests, a BVH is a data structure that is used to quickly compute collision queries for a set of polygons. It doesn't usually provide information about the underlying geometry itself other than possibly maintaining references to triangles in the leaves of the tree. In terms of your problem of finding out whether or not a point is within a set ...


1

There are two things to take care of: Direction of a ray vector in accordance to triangle windings Actual representation of a ray vector ad. 1) Seems like gml::intersectLineTriangle() function needs a ray vector to point to a front face of a CCW triangle to work. This is not the case in Your code and You can do two things to fix it: originate a ray ...


1

Your ray is possibly in view (camera) space. I'm unsure exactly how glm::unproject works. If I'm right, pass its end points through the inverse camera matrix to put then in world space. Remember that a coordinate is expressed in some basis, which for our purposes can be considered a vector space (mathematically there is some difference) or commonly just a ...


1

You need to find penetration distance and an axis of resolution. The axis of resolution will be the axis of least penetration between the two objects. Finding this information is non-trivial and makes for a much more in-depth implementation than the one you currently have. See Box2D Lite for an example of an OBB to OBB test. For a working generalized ...


1

That's not so bad if you know the position of A and B at all times. Example: A is at the origin. B is traveling around the origin at a distance of 1. (ie, it's orbit is the unit circle) Let Y be the object leaving A. Let the speed of B be such that every second B crosses an axis. So the period of B is 4 seconds. Therefore the position of B at any given ...


1

Mathematical explanation with readable symbols and LaTeX format - great for 1st or 2nd year undergrad students or skilled high-school people. Well, if you need to understand the maths behind it rather than copy-pasting some code that might not be the good one (it's not clear whether it will work or not judging from the SO code). Here are the steps: It's ...


1

Without looking at the code in much detail, I'm going to take a guess that your triangle intersection routine only works from one side of the triangle, but your triangle "mesh" describes triangles with opposite "handedness" (if v0,v1,v2 is clockwise, then v1,v2,v3 is anticlockwise as seen by a ray from the same direction). This could be confirmed by e.g ...


1

Searching for "aim at moving target": Aiming and hitting a moving target /** * Shoot at a target * * @param t The target to be shot * @return The bullet to be fired (or null if cannot hit) */ public function shoot(targ:Target, bulletSpeed:Number = BULLET_SPEED):Bullet { var dx:Number = targ.x - this.x; var dy:Number = targ.y - this.y; ...



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