Hello 3DRad community,
I am doing a project (originally using AircrafDemo_autobalance.3dr project)that makes a UAV flies automatically from point A to point B..Where it will:
Take off automatically
Check the locations of the Target (x1,y1,z1) and the UAV (x2,y2,z2) via iOjectLocation
Get the theta in cos(theta) where theta = dotproduct/(lengthUAV*lengthTarget)
Now the problem is I am getting a very big angle and the UAV is turning accordingly to the other side of the map, beyond the target.
I checked into it and found that the dot product (which is suppose to be from -1 to 1) is very huge no matter what option I choose (iVectorDot or the formula) which led me to this question:
what does iObjectLocation(OBJ_X,Vector3) really gives
PN: thanks to all who helped me in the previous post, also I am new to the 3DRad community, if I posted in the wrong thread, please kindly advice me
Regards,
Forat
I am doing a project (originally using AircrafDemo_autobalance.3dr project)that makes a UAV flies automatically from point A to point B..Where it will:
Take off automatically
Check the locations of the Target (x1,y1,z1) and the UAV (x2,y2,z2) via iOjectLocation
Code: [Select]
void Position_target ()
{
iObjectLocation(OBJ_458,Ball);
}
void Position_plane ()
{
Vector3 Location_propeller;
Vector3 Location_elevator;
Vector3 Location_rudder;
Vector3 Location_rightaileron;
Vector3 Location_leftaileron;
iObjectLocation(OBJ_0,Location_propeller);
iObjectLocation(OBJ_18,Location_elevator);
iObjectLocation(OBJ_40,Location_rudder);
iObjectLocation(OBJ_62,Location_rightaileron);
iObjectLocation(OBJ_84,Location_leftaileron);
Location.x = (Location_propeller.x + Location_elevator.x + Location_rudder.x + Location_rightaileron.x + Location_leftaileron.x)/5;
Location.y = (Location_propeller.y + Location_elevator.y + Location_rudder.y + Location_rightaileron.y + Location_leftaileron.y)/5;
Location.z = (Location_propeller.z + Location_elevator.z + Location_rudder.z + Location_rightaileron.z + Location_leftaileron.z)/5;
}
Get the length of the 2 vectors (from the origin ) using iVectorLength () or float = iFloatSqrt(x*x+y*y+z*z)Code: [Select]
void length ()
{
lengthUAV = iFloatSqrt(Location.x*Location.x + Location.y*Location.y + Location.z*Location.z);
//lengthUAV = iVectorLength(Location);
lengthTarget = iFloatSqrt(Ball.x*Ball.x + Ball.y*Ball.y + Ball.z*Ball.z);
//lengthTarget = iVectorLength(Ball);
}
Get the dot product between them using iVectorDot() or float = x1*x2+y1*y2+z1*z2Get the theta in cos(theta) where theta = dotproduct/(lengthUAV*lengthTarget)
Code: [Select]
oid dot_product ()
{
//[UAVx UAVy UAVz].[Targetx Targety Targetz]
//dotproduct = Location.x*Ball.x + Location.y*Ball.y + Location.z*Ball.z;
// iVectorLengthSet(nLocation,Location,1);
// iVectorLengthSet(nBall,Ball,1);
dotproduct = iVectorDot(Location,Ball);
dot = dotproduct/(lengthUAV*lengthTarget);
arc_cos (dot);
}
Get theta via a_cos(theta) by using MathRad.dllCode: [Select]
float arc_cos (float value)
{
iDLLArraySet(0,value);
iDLLCall(MathDLLHandle,"R_acos",0);
angle = iDLLArrayGet(0);
return angle;
}
Now the problem is I am getting a very big angle and the UAV is turning accordingly to the other side of the map, beyond the target.
I checked into it and found that the dot product (which is suppose to be from -1 to 1) is very huge no matter what option I choose (iVectorDot or the formula) which led me to this question:
what does iObjectLocation(OBJ_X,Vector3) really gives
PN: thanks to all who helped me in the previous post, also I am new to the 3DRad community, if I posted in the wrong thread, please kindly advice me
Regards,
Forat