Reputation: 305
I have a sphere with a center in (0,0,0) and radius = 1, with three marked points on it's surface, forming a triangle:
x = (1,0,0)
y = (0,1,0)
z = (0,0,1)
Now, I am translating y by a vector v_y to get y'
v_y = [1, 2, 3]
y' = (1, 3, 3)
I want to calculate v_x and v_z the way, both x' and z' will move in the same manner, so calculated points will form simillar triangle (same side to side ratios)
I know it can be achieved by rotating, and scaling this sphere, but I have no idea how to calculate this just by knowing this vector. I need two angles for rotation, and one scalar for scaling.
Maybe I am wrong, and I can just calculate those vectors without calculating a rotation.
Upvotes: 0
Views: 525
Reputation: 974
I think I get what you are trying to do here. You are adding v_y to y to form y' and you want the x and z (perpendicular vectors) to stay perpendicular and relatively increase in length to reach the circumference of the sphere which is now scaled.
I will do this in two parts, scale and rotate. note that y2
in code is your y'. I use glm
here but you can replace with your own math library.
//compute y2
glm::vec3 y2 = y + v_y;
//compute the scale
float scale = glm::length(y2) / glm::length(y);
//compute the scaled x and z
glm::vec3 x2 = x * scale;
glm::vec3 z2 = z * scale;
//find the normal and angle and arc as a quaternion
glm::vec3 ynorm = cross(y, glm::normalize(y2));
float angle = glm::angle(y, glm::normalize(y2));
glm::quat arcQuat = glm::angleAxis(angle, ynorm);
//now rotate x2 and z2 with the above arc
x2 = glm::gtx::quaternion::rotate(arcQuat, x2);
z2 = glm::gtx::quaternion::rotate(arcQuat, z2);
//now you have your v_x and v_z
glm::vec3 v_x = x2 - x;
glm::vec3 v_z = z2 - z;
If you scale your sphere by scale, x2, y2 and z2 will form a similar triangle that you want.
Upvotes: 1
Reputation: 12069
It's impossible to know how to create the other vertices without knowing what transformation you think you actually applied, and hence how you expect the other verts to move.
Based on a single original point and a single new point, you only describe the radius and one axis of the sphere's orientation (the vector between origin and y'). However, it's ambiguous about the rotation of the second axis you need to concretely define a precise transform. You can rotate the new sphere 360 degrees around the vector between the origin and the y', and any of those values on a 360 degree arc would describe valid values of x' and z'.
Upvotes: 1