I'm trying to work out how to create a new vector position or destination vector position to represent an extracted section of a circle (or piece of pie) given the current angle. Specifically I need to work out the total float value needed to reach the destination vector from the current vector by incrementing x and y per frame for my animation - (this part is already done just some background info). I have already determined the following bits of information in my program...here's a sample:
- Vector Start: x 1.000000 y 0.000000 z 0.200000
- Vector End: 0.406737 y 0.913545 z 0.200000
- crossproduct. x 0.182709, y 0.118653, z -0.913545
- Start Angle In Degrees: 0.000000
- End Angle In Degrees: 66.000000
- Angle between vector start and end in degrees: 33
I've tried using the method below to increment/decrement positions
float distanceX = (crossProduct.x > 0) ? crossProduct.x + 0.5 : crossProduct.x - 0.5;
float distanceY = (crossProduct.y > 0) ? crossProduct.y + 0.5 : crossProduct.y - 0.5;
and then applying:
translationX = cosf(distanceX) * 1;
translationY = sinf(distanceY) * 1;
translationX /= 10;
translationY /= 10;
to get: translationX: 0.077587 translationY: 0.057994
finally the new coordinates are passed into:
glTranslatef(translationX, translationY, 0.0);
This code works on some level but I run into trouble when applying it to different parts of the circle i.e. quadrants where some sectors are in share quadrants.
Thanks for all the responses. Here is the implemented code as suggested by @Mark Oblak.
GLKVector4 normalizedVectorStart = GLKVector4Normalize(vStart);
GLKVector4 normalizedVectorEnd = GLKVector4Normalize(vEnd);
GLKVector4 vectorOffset = GLKVector4Add(normalizedVectorStart, normalizedVectorEnd);
GLKVector4 normalizedVectorOffset = GLKVector4Normalize(vectorOffset);
NSLog(@"normalizedVectorOffset x %f y %f z%f", normalizedVectorOffset.x, normalizedVectorOffset.y, normalizedVectorOffset.z);
normalizedVectorOffset x 0.532707 y 0.345944 z0.151473
float sign = GLKVector4DotProduct(normalizedVectorOffset, vStart);
float distanceFromCenter = 0.2;
sign = (sign > 0.0) ? 1.0 : -1.0;
GLKVector4 normalizedVectorOffsetWithSign = GLKVector4MultiplyScalar(normalizedVectorOffset, sign * distanceFromCenter);
NSLog(@"normalizedVectorOffset (sign) x %f y %f z%f", normalizedVectorOffsetWithSign.x, normalizedVectorOffsetWithSign.y, normalizedVectorOffsetWithSign.z);
normalizedVectorOffset (sign) x 0.106541 y 0.069189 z0.030295