Skip to main content

All Questions

Filter by
Sorted by
Tagged with
7 votes
2 answers
784 views

Calculating the moment of inertia of a 2D convex polygon for physics

I have made a quick and basic working demo on calculating the moment of inertia of a 2D convex polygon. This was for the purpose of learning physics engines, more specifically rigid body dynamics (2D) ...
kasjolaman's user avatar
4 votes
2 answers
683 views

Computing bezier curves of degree n with recursive functions

I have been looking at homemade CNC and have been wondering how curves are drawn, so I looked into it and found this cool article. I then decided to try coming up with a bezier curve algorithm in C. ...
user233009's user avatar
7 votes
3 answers
4k views

Compute shortest distance between point and a rectangle

I want to compute the shortest distance between a position (x,y) and a rectangular box defined by (x_min, y_min) and (x_max, y_max). See the picture below with some examples. I know that in two ...
Gilfoyle's user avatar
  • 1,167
7 votes
2 answers
106 views

Parametrization of a curve

For a set of 2D or 3D points \$\{\mathbf P_0, \mathbf P_1,\cdots,\mathbf P_n\}\$, their parameters \$\mathbf T = \{t_0,t_1,\cdots,t_n \}\$ could be computed as follow: $$\begin{align} t_0&=0\\ ...
xyz's user avatar
  • 227
10 votes
3 answers
1k views

Check if 2 rectangles fit in another one, given their length and height

I was very intrigued with the manner to solve this problem. The program needs to know if 2 rectangles fit in another one, considering the lines of the 2 rectangles are always parallel to the other one'...
Lúcio Cardoso's user avatar
6 votes
2 answers
438 views

Quaternion rotations and preparing matrices for a shader

I am implementing an OpenGL ES 2.0 renderer in c. I want to use quaternions for rotations. Please take a look at the way I am implementing the rotation math. Everything looks as expected when the ...
steven's user avatar
  • 161
7 votes
3 answers
568 views

Optimizing a loop in C for a microcontroller

I am trying to draw a Checkerboard pattern on a LCD using a GUI library called emWin. I have actually managed to draw it using the following code. But having this many loops in the program body for a ...
WedaPashi's user avatar
  • 213
2 votes
1 answer
2k views

Finding the pairs of intersecting discs

I have been following this question on SO, copied below. I put together a solution, but which is \$O(n^2)\$. In order to get a more efficient \$O(n \log n)\$ or \$O(\log n)\$ solution, I tried to ...
goldenmean's user avatar