Clamping a vector to a minimum and maximum?

Posted by user146780 on Stack Overflow See other posts from Stack Overflow or by user146780
Published on 2010-06-09T19:36:21Z Indexed on 2010/06/09 19:42 UTC
Read the original article Hit count: 252

Filed under:
|
|

I came accross this: t = Clamp(t/d, 0, 1) but I'm not sure how to perform this operation on a vector. What are the steps to clamp a vector if one was writing their own vector implementation?

Thanks

clamp clamping a vector to a minimum and a maximum

ex:

pc = # the point you are coloring now
p0 = # start point
p1 = # end point
v = p1 - p0
d = Length(v)
v = Normalize(v) # or Scale(v, 1/d)

v0 = pc - p0

t = Dot(v0, v)
t = Clamp(t/d, 0, 1)

color = (start_color * t) + (end_color * (1 - t))

© Stack Overflow or respective owner

Related posts about c++

Related posts about c