Advertisement

Math problem with circular image (radians, not evenly spaced?)

Started by March 12, 2020 06:31 PM
18 comments, last by suliman 4 years, 10 months ago

No, h is 0.5, which means the triangle runs all the way up until the rectangle.

EDIT: it's v rather than h, sorry.

tan() gives a relation between v and h, you can scale both length to whatever you need to have.

“tan(angle)" is v/h by definition. At 45 degrees, tan() is 1. That does not mean v and h are both 1, it means h==v (since then v/h == 1). If you pick h = 1000, then v must be 1000 too, etc.

if tan(angle) == 2, then v must be twice as big as h. The relation holds for any angle.

tan(angle) = v/h
h * tan(angle) = v
v = 0.5
h = v / tan(angle)  ≤=> h = 0.5 / angle

Advertisement

https://www.mathsisfun.com/sine-cosine-tangent.html

Pythagoras: a*a = h*h + v*v

None

Im still confused. I know the hypotenuse is always 1, since its on the circle, but i need the length of that line enlongened to get to the point on the rectangle for any angle.

In my example pic the length should be around 1.2 but how do i get it for any angle?

suliman said:
Im still confused. I know the hypotenuse is always 1, since its on the circle

Except your circle is not the unit circle, it has radius 0.5, or else it doesnot fit in the rectangle (0, 0) - (1, 1). Unit circle with radius 1 runs from (-1, -1) to (1, 1), with the center at (0, 0).

The circle isn't relevant, only the triangle is. You get the length of the line at an angle by pythagoras if you know the lengths of the horizontal and vertical lines. For less than 45 degrees, the vertical line v = 0.5 from the center. The horizontal length is given by the the ratio c = tan(angle) which is by definition c = h/v. That makes h the only unknown.

(switching to code block, as text is just too horrible for any math with a multiplication sign in it)

c = h/v thus v * c = h (multiply both sides by v).

Also, c = tan(angle), and v = 0.5. Therefore  v * c = 0.5 * tan(angle) = h
[for angles ≤ 45 degrees, otherwise v=0.5 doesn't hold]

Length of the line is (pythagoras) a*a = v*V + h*h, thus a = sqrt(v*V + h*h).
I am not sure why you need that though, since you have all coordinates:
center at (0.5, 0.5)
top of v is 0.5 above that (0.5, 1.0)
end of h to the right of top of v (0.5 + h, 1.0)  [still for ≤ 45 degrees]

Advertisement

I couldnt get it to work, maybe my translations in the reference system throws me off. I ended up forcing it:

	while (abs(p[2].x) < 0.5 && abs(p[2].y) < 0.5) {
		p[2].x *= 1.01;
		p[2].y *= 1.01;
	}

After setting the mid of the circle in the 0,0 point, i just enlong both dimensions of the point until one of them reaches abs(0.5). It's not pretty but i do find the right point for any angle ?

Quite ? , but it works.

You can compute the multiplication factor in a single step. The only risk is if p[2] is very near the origin, but that doesn't happen.

float c = max(abs(p[2].x), abs(p[2].y));
if (c < 0.5) {
  float f = 0.5 / c; // Factor to go from length c to 0.5 .
  p[2].x *= f;
  p[2].y *= f;
}

EDIT: I think the ‘if’ isn't even needed, it should always work (even if c ≥ 0.5) as long as p[2] is not very close to the origin.

Yes that is prettier for sure, thanks!

This topic is closed to new replies.

Advertisement