[Closed] Creating a new vector between two vectors
hello,
in my eternal struggle to understand matrix calculations i was just thinking about a couple of the tutorials in the MXS help. If i have two vectors, both from the same start point, eg A-B and A-C i can obviously calulate the angle between them with the acos dotty normal thingy.
Say if you wanted to make another vector from these, (A-D) but from the same start point but halfway between the first two? when i say halfway i mean a vector with half of angle of the first two. i was just thinking in terms of making a point constrain to the perimeter of a circle, and have another lock to the same perimeter only inbetween the start point and this constrained point?
Assuming the vectors are normalized, you can add them together to get the angle halfway between (the half angle), and normalize that.
Hi Rob,
Thanks for your reply. That works perfectly. So just to take this further, say you had these two original vectors and wanted to specify say, five new vectors between the two of them. Once you have the angle between them, could you divide this into the angle increments you needed and use trig to get the new vectors from the first vector or am i thinking wrong?
am not sure I fully grasped what you mean, but this is what I understand from your post:
you need a new vector AD to be created angularly between AB and AC
Since you spoke of perimeter of a circle, I am assuming that AB and AC can be considered to be radii of the circle, and you need the length of the new vector to be the same as the radius
(B-D-C can only be part of a circle if length AB == length AD == length AC)
if O is the origin,
OX =(OB + OC)/2 would give you a vector from the origin to X (midpoint of B and C)
The position defined by this vector, though lies between B and C, will not lie on the circle you want, but if we make the length of this vector equal to the length of either AB or AC, then it will.
try running this each line:
A = teapot pos:[-1.61, 50.896, 58.079] radius:5
B = sphere pos:[-30.9297,89.1222,71.4613] radius:5
C = sphere pos:[29.1172,61.1276,96.1731] radius:5
X = sphere radius:3
D = sphere radius:3
radius = length (A.pos - B.pos)
OX = (B.pos + C.pos)/2
X.pos = OX
AX = X.pos - A.pos
D.pos = A.pos + (normalize(AX) * radius)
circ = circle radius:50
circ.transform = (matrix3 [-0.614539,-0.204635,-0.761883] [-0.586398,0.764528,0.267647] [0.527711,0.611246,-0.58983] [-1.60977,50.8958,58.079])
Hi Shibu, yes , that is the kind of thing i was thinking of. when i spoke of the circle perimeter, i was thinking that as a way of applying this method. I had assumed that once i had calculated normalized vectors the magnitude (or multiplier) would then be the circle’s radius, allowing me to position them accordingly. thanks for your input.
I thought if,
you got the angle between b and c using a simple dot product you could slice it up into chunks: angle = 60 degrees; 10 chunks = 6 degrees
all you’d need to do is transform b about a using matrix multiplication
n1 = normalize (b.pos – a.pos)
n2 = normalize (c.pos – a.pos)
angle = acos(dot n1 n2)
tm = (b.transform * inverse a.transform)
divs = angle/10 as integer
for i = 1 to divs do
(
newPoint = point()
newPoint.transform = tm * (((eulerangles 0 0 (divs*i)) as matrix3) * a.transform)
)
you could also just lerp between b and c, normalize that vector then mulitiply it by the length:
e.g.
t = 0.5
a = a.transform.pos
b = b.transform.pos
c = c.transform.pos
n = (((normalize ((1-t)*b + t * c)) * (distance b a)) + a)
Hello Charles,
Many thanks for your time and your interesting reply. I was reading about lerps and slerps in my essential mathematics for games programmers book – it is a bit above my maths level but i try to follow the best i can. I like the lerp method, although I haven’t tested your code yet.
I was thinking about how this sort of thing could be implemented. As a technique, i wondered if it is a similar concept to the ambient occlusion calculation, as essentially from a point, the angle between two vectors represent the spread of the AO pass. the magnitude of the vector is the same as the maximum distance for the AO, and the distribution of the interpolated vectors are like the number of samples.
In terms of any application of this for rigging, i wondered about whether this could be employed for any form of staggered, circular rotation like an eyeball deformation curve or a twist rig for a forearm or similar. just my musings really, forgive their vagaries…