• Create Account

Member Since 28 Feb 2013
Offline Last Active Mar 10 2014 01:50 PM

### In Topic: Unity-like transform component

19 February 2014 - 10:22 AM

I've never messed around with Unity, but I would store the world rotation matrix separately and postmultiply the rotation component matrix onto the world rotation matrix before drawing (Rot * World = MV). If I need to rotate in the world coordinate frame, I could premultiply the rotation matrix with the new matrix ([Rot * NewWorld] * World = MV). If I need to multiply in the local frame, I would postmultiply ([NewLocal * Rot] * World = MV).

Hope that helps spark discussion.

### In Topic: Unity-like transform component

03 February 2014 - 10:55 AM

Is there a framework that you're using or are you creating something like that in DirectX/OpenGL/etc?

### In Topic: Epsilon on determinant

24 January 2014 - 10:56 AM

It really depends on your algorithm and your numeric types. There's lots of algorithms that evaluate determinants. Some algorithms can handle high tolerances for epsilon, like 1e-12. Using floats instead of doubles limits the accuracy of the arithmetic, so high tolerances are probably not going to mean much. That all has to be taken into account. Like you probably know, you never want to just test for exact equivalence to zero unless you're testing for a very specific case.

det = vdot(Mk[0], MadjTk[0]);
if (det==0.0) {do_rank2(Mk, MadjTk, Mk); break;}


In Ken Shoemake's code above, he's just avoiding dividing by zero exception with the "if (det == 0)" check. It seems the algorithm can work for incredibly small numbers, so you don't need anything else other than just avoiding division by zero. Besides, he's using the vdot() function, which as far as I can tell isn't a determinant algorithm, but rather a dot product operation.

### In Topic: Solve path around a given point and radius

14 January 2014 - 06:44 PM

Here's a fairly decent way to solve this problem. I'm assuming this will be a "line,circle,line" problem, but you can alter this for different cases. I would put the line into parametric form and the circle into implicit form:

$C(t) = (x-a)^2 + (y-b)^2 - r^2 = 0; L(x(t),y(t)) = [x_0 + ct, y_0+dt]$

Here, $$(a,b)$$ is the center of the circle, $$r$$ is the radius, and $$(x_0,y_0)$$ is the start point of the path and your direction vector $$V_1 = (c,d)$$. By substituting the parametric line formulas into the implicit circle formula, we can get a polynomial whose roots are the intersection points in the line parameter space:

\begin{aligned} (x_0+ct-a)^2 + (y_0+dt-b)^2 -r^2 &= 0 \\ (c^2+d^2)t^2+2[c(x_0-a)+(y_0-b)]t+[(x_0-a)^2+(y_0-b)^2-r^2] &= 0 \\ At^2+Bt+c &= 0 \\ \end{aligned}

The roots can be solved for quickly using the quadratic equation:

$t = \frac{-B\pm \sqrt{B^2-4AC}}{2A}$

If the discriminant $$B^2 - 4AC < 0$$, then you have no intersections. If  $$B^2 - 4AC = 0$$, you've got 1 intersection. If  $$B^2 - 4AC > 0$$, you've got 2 intersections, which is really the only case you have to worry about to avoid the object since the path can stay linear for any other cases. You can then evaluate the parametric line at the roots of the polynomial to get the intersection points in (x,y) form. You can get the angles of the points on the circle using $$\theta = \text{atan2}(y-b, x-a)$$. If the problem is as shown in the OP's picture (where the starting path point isn't inside the circle), you also know which point to start from and which point to end with because the point with the lesser parameter value t is the point closest to $$(x_0,y_0)$$.

Deciding which path around the circle is shorter is the last issue to resolve. We could calculate arc length, but we can figure out which way to go by using the implicit form of the line and figuring out which side of the line the circle's center is. The implicit line formula is given by $$\mathcal{A}x+\mathcal{B}y+\mathcal{C}=0$$. The coefficients for the implicit line are simple to calculate from the parametric form: $$\mathcal{A} = -d, \,\mathcal{B} = c, \,\mathcal{C} = dx_0-cy_0$$. The equation then becomes $$D = d(x_0-a)+c(b-y_0)$$. If D < 0, then the circle center is on the right side of the line (looking in the direction of the line). That means the clockwise path around the circle is the shortest path. If D > 0, then the circle center is on the left side of the line, which means the counterclockwise path is the shortest. If D = 0, then the circle center lies on the line and each path is the same length.

You can step with constant velocity along the path by using the parametric form of the line and along the circle by figuring out your angle step via $$ds = r d\theta$$. As I see it, this is fairly elegant because there's nothing more than additions, multiplications, atan2, and a square root function, making it a fairly fast method.

Hope that helps!

### In Topic: Sorting (mathematical) vectors in list

02 January 2014 - 11:38 AM

You could create a sort method that takes in a lambda expression so you can sort differently depending on your case. I can envision a lot of ways to sort vectors (by length, by coordinate, by dot product with another vector, etc.) so you might want to keep your options open.

PARTNERS