stackgl / shader-school

:mortar_board: A workshopper for GLSL shaders and graphics programming
Other
4.28k stars 252 forks source link

intro-3 question #119

Closed corbmanj closed 9 years ago

corbmanj commented 9 years ago

I can get a solution to this exercise if I use the relation that the sum of two normalized vectors is the angle bisector and then normalize this for the return.

return normalize(vec2(length(b)*a.x+length(a)*b.x, length(b)*a.y+length(a)*b.y;

This satisfies the exercise, but it does not seem to use the suggested relation:

length(B - C) / length(C - A) == length(B) / length(A)

Can someone please explain to me how to use this relation to solve this exercise? I may just be misunderstanding how to distribute the length function. For instance, it does not seem plausible from a geometry standpoint that length(B-C) == length(B)-length(C)

Note: I also tried solving for the equation of the line AB and trying to solve for the point C such that the ratio of the distance BC:AC was equal to the ratio of length(B):length(A), but that took me down a rabbit hole with one equation and two unknowns.

grn94 commented 9 years ago

highp vec2 func(highp vec2 a, highp vec2 b) { //TODO: Implement the exercise here // Let length of a = |a| and length of b = |b| // and L = length of a - b // and |x| be the length of that part of the a - b where angles of equal // then // |a|/|b| = |x| / (L-|x|) (specified the by angle bisector theorem // solving for |x|/L = gives the variable s specified below. // highp float s = length(a) / (length(a) + length(b)); highp vec2 c = a - (a - b) * s; return normalize(c); }