Hi,
I have an origin vessel and a target vessel which is moving relative to the origin vessel in relatively close vicinity. Now I want a third vessel to move on an intercept course from the origin to the target vessel. I think that I have the calculation of the aimpoint right but I cannot figure out how I change the intercept vessel's velocity so that it moves towards the calculated aimpoint.
1. is it in principle correct to do this with the DefSetState function?
2. I do the calculation of the aimpoints with the rvel and rpos attributes from the VESSELSTATE structure which are relative to the body being orbited, correct?
3. Subtracting the aimpoint from the origin vessel's position gives a vector from the origin to the aimpoint, right? Normalising this vector and multiplying it with the desired intercept velocity (used in the calculation of the aimpoint) would be the velocity vector of the intercept vessel relative to the origin if it were motionless, right?
How do I convert this to a vector which can be properly used in the VESSELSTATE? I tried Local2Rel but it results in a very lengthy vector, i. e. something in my code - and understanding of the refernce frames - is not correct.
Edit: I think it would be enough to add the course vector to the origin vessel's VESSELSTATUS.rvel vector but the components of the coordinates are twisted?
I have an origin vessel and a target vessel which is moving relative to the origin vessel in relatively close vicinity. Now I want a third vessel to move on an intercept course from the origin to the target vessel. I think that I have the calculation of the aimpoint right but I cannot figure out how I change the intercept vessel's velocity so that it moves towards the calculated aimpoint.
1. is it in principle correct to do this with the DefSetState function?
2. I do the calculation of the aimpoints with the rvel and rpos attributes from the VESSELSTATE structure which are relative to the body being orbited, correct?
3. Subtracting the aimpoint from the origin vessel's position gives a vector from the origin to the aimpoint, right? Normalising this vector and multiplying it with the desired intercept velocity (used in the calculation of the aimpoint) would be the velocity vector of the intercept vessel relative to the origin if it were motionless, right?
How do I convert this to a vector which can be properly used in the VESSELSTATE? I tried Local2Rel but it results in a very lengthy vector, i. e. something in my code - and understanding of the refernce frames - is not correct.
Code:
double AimAhead(VECTOR3 delta, VECTOR3 vr, double interceptV) {
double a = dotp(vr, vr) - interceptV * interceptV;
double b = 2.0 * dotp(vr, delta);
double c = dotp(delta, delta);
double det = b*b - 4.0 * a * c;
if(det > 0.0) {
return 2.0 * c / (sqrt(det) - b);
} else {
return -1.0f;
}
}
VECTOR3 targetPos, originPos, targetVelocity, originVelocity, delta, cv;
VESSELSTATUS vs;
VESSEL * originInterface = oapiGetFocusInterface();
OBJHANDLE originHandle = originInterface->GetHandle();
originInterface->GetStatus(vs);
originPos = vs.rpos;
originVelocity = vs.rvel;
vs.rpos.z += 100;
vs.rvel.x += 10;
VESSEL * targetInterface;
OBJHANDLE targetHandle = oapiCreateVessel("Target", "ShuttlePB", vs);
targetInterface = oapiGetVesselInterface(targetHandle);
targetInterface->GetStatus(vs);
targetPos = vs.rpos;
targetVelocity = vs.rvel;
originInterface->GetStatus(vs);
VESSEL * interceptInterface;
OBJHANDLE interceptHandle = oapiCreateVessel("Intercept", "Carina", vs);
interceptInterface = oapiGetVesselInterface(interceptHandle);
delta = targetPos - originPos;
cv = targetVelocity - originVelocity;
double interceptV = 15.0;
double t = AimAhead(delta, cv, interceptV);
if(t > 0.0) {
VECTOR3 aimpoint = targetPos + (cv * t);
VECTOR3 course = originPos - aimpoint;
normalise(course);
course = course * interceptV;
Local2Rel(course, vs.rvel);
interceptInterface->DefSetState(&vs);
}
Edit: I think it would be enough to add the course vector to the origin vessel's VESSELSTATUS.rvel vector but the components of the coordinates are twisted?
Last edited: