Calculate xyz velocity vectors for circular orbit

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I'm trying to calculate the xyz velocity vectors for a circular orbit given a set of position vectors, but I can't seem to get it right.



The formula for obtaining the velocity magnitude is the square root of gravitational constant multiplied by the mass of the primary divided by the distance from the primary to the object orbiting it. I'm using solar masses for mass, astronomical units for distance and years for time. To simplify things, the primary is our sun, which means that G * M is equal to 39.5. The position of the Sun is 0, 0, 0 and the vectors you see for Earth are in au and were obtained from the JPL Horizons tool.



Here's the code:



 function getDistanceParams(p1, p2) 
const dx = p2.x - p1.x;
const dy = p2.y - p1.y;
const dz = p2.z - p1.z;

return dx, dy, dz, dSquared: dx * dx + dy * dy + dz * dz ;


function getCircularOrbit()
const dParams = getDistanceParams(
x: 0, y: 0, z: 0 ,

x: 0.9197324105567349,
y: -0.4147318273536994,
z: -1.750037390352759e-5

);

const vMag = Math.sqrt(39.5 / Math.sqrt(dParams.dSquared));

return vx: dParams.dx * vMag, vy: dParams.dy * vMag, vz: dParams.dz * vMag;


getCircularOrbit();

/*

The above outputs this:

vx: 5.754832301294686,
vy: -2.59500707927136,
vz: -0.00010950110691846996

The actual velocity vectors:

vx: 2.4645428337894026,
vy: 5.7097644117945805,
vz: -3.3177815766459033e-4,

*/


Where am I going wrong???










share|cite|improve this question























  • Can you write the math equations here? After we (or math stackexchange) check that, go to stackoverflow to check if your programming is same as the math equation.
    – R zu
    3 hours ago















up vote
1
down vote

favorite












I'm trying to calculate the xyz velocity vectors for a circular orbit given a set of position vectors, but I can't seem to get it right.



The formula for obtaining the velocity magnitude is the square root of gravitational constant multiplied by the mass of the primary divided by the distance from the primary to the object orbiting it. I'm using solar masses for mass, astronomical units for distance and years for time. To simplify things, the primary is our sun, which means that G * M is equal to 39.5. The position of the Sun is 0, 0, 0 and the vectors you see for Earth are in au and were obtained from the JPL Horizons tool.



Here's the code:



 function getDistanceParams(p1, p2) 
const dx = p2.x - p1.x;
const dy = p2.y - p1.y;
const dz = p2.z - p1.z;

return dx, dy, dz, dSquared: dx * dx + dy * dy + dz * dz ;


function getCircularOrbit()
const dParams = getDistanceParams(
x: 0, y: 0, z: 0 ,

x: 0.9197324105567349,
y: -0.4147318273536994,
z: -1.750037390352759e-5

);

const vMag = Math.sqrt(39.5 / Math.sqrt(dParams.dSquared));

return vx: dParams.dx * vMag, vy: dParams.dy * vMag, vz: dParams.dz * vMag;


getCircularOrbit();

/*

The above outputs this:

vx: 5.754832301294686,
vy: -2.59500707927136,
vz: -0.00010950110691846996

The actual velocity vectors:

vx: 2.4645428337894026,
vy: 5.7097644117945805,
vz: -3.3177815766459033e-4,

*/


Where am I going wrong???










share|cite|improve this question























  • Can you write the math equations here? After we (or math stackexchange) check that, go to stackoverflow to check if your programming is same as the math equation.
    – R zu
    3 hours ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm trying to calculate the xyz velocity vectors for a circular orbit given a set of position vectors, but I can't seem to get it right.



The formula for obtaining the velocity magnitude is the square root of gravitational constant multiplied by the mass of the primary divided by the distance from the primary to the object orbiting it. I'm using solar masses for mass, astronomical units for distance and years for time. To simplify things, the primary is our sun, which means that G * M is equal to 39.5. The position of the Sun is 0, 0, 0 and the vectors you see for Earth are in au and were obtained from the JPL Horizons tool.



Here's the code:



 function getDistanceParams(p1, p2) 
const dx = p2.x - p1.x;
const dy = p2.y - p1.y;
const dz = p2.z - p1.z;

return dx, dy, dz, dSquared: dx * dx + dy * dy + dz * dz ;


function getCircularOrbit()
const dParams = getDistanceParams(
x: 0, y: 0, z: 0 ,

x: 0.9197324105567349,
y: -0.4147318273536994,
z: -1.750037390352759e-5

);

const vMag = Math.sqrt(39.5 / Math.sqrt(dParams.dSquared));

return vx: dParams.dx * vMag, vy: dParams.dy * vMag, vz: dParams.dz * vMag;


getCircularOrbit();

/*

The above outputs this:

vx: 5.754832301294686,
vy: -2.59500707927136,
vz: -0.00010950110691846996

The actual velocity vectors:

vx: 2.4645428337894026,
vy: 5.7097644117945805,
vz: -3.3177815766459033e-4,

*/


Where am I going wrong???










share|cite|improve this question















I'm trying to calculate the xyz velocity vectors for a circular orbit given a set of position vectors, but I can't seem to get it right.



The formula for obtaining the velocity magnitude is the square root of gravitational constant multiplied by the mass of the primary divided by the distance from the primary to the object orbiting it. I'm using solar masses for mass, astronomical units for distance and years for time. To simplify things, the primary is our sun, which means that G * M is equal to 39.5. The position of the Sun is 0, 0, 0 and the vectors you see for Earth are in au and were obtained from the JPL Horizons tool.



Here's the code:



 function getDistanceParams(p1, p2) 
const dx = p2.x - p1.x;
const dy = p2.y - p1.y;
const dz = p2.z - p1.z;

return dx, dy, dz, dSquared: dx * dx + dy * dy + dz * dz ;


function getCircularOrbit()
const dParams = getDistanceParams(
x: 0, y: 0, z: 0 ,

x: 0.9197324105567349,
y: -0.4147318273536994,
z: -1.750037390352759e-5

);

const vMag = Math.sqrt(39.5 / Math.sqrt(dParams.dSquared));

return vx: dParams.dx * vMag, vy: dParams.dy * vMag, vz: dParams.dz * vMag;


getCircularOrbit();

/*

The above outputs this:

vx: 5.754832301294686,
vy: -2.59500707927136,
vz: -0.00010950110691846996

The actual velocity vectors:

vx: 2.4645428337894026,
vy: 5.7097644117945805,
vz: -3.3177815766459033e-4,

*/


Where am I going wrong???







vector






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited 3 hours ago

























asked 3 hours ago









Happy Koala

1135




1135











  • Can you write the math equations here? After we (or math stackexchange) check that, go to stackoverflow to check if your programming is same as the math equation.
    – R zu
    3 hours ago

















  • Can you write the math equations here? After we (or math stackexchange) check that, go to stackoverflow to check if your programming is same as the math equation.
    – R zu
    3 hours ago
















Can you write the math equations here? After we (or math stackexchange) check that, go to stackoverflow to check if your programming is same as the math equation.
– R zu
3 hours ago





Can you write the math equations here? After we (or math stackexchange) check that, go to stackoverflow to check if your programming is same as the math equation.
– R zu
3 hours ago











1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










In your code, you seem to be calculating the magnitude $|vecv|$ of the velocity (the speed) from your gravitational formula and multiplying it by the components of the position vector $vecr$. There are two errors here.



  1. You need to multiply the speed by a unit vector in the direction of the velocity, in order to get the velocity vector $vecv$. In general the
    position vector is not a unit vector (actually in this case, it is pretty close, because you chose astronomical units, but that is just luck).

  2. The position vector $vecr$ is pointing in a radial direction, whereas the velocity vector $vecv$ (for circular motion)
    lies in a tangential direction.

You are not actually inputting to your program enough information to work out the direction of the velocity vector. You need to know the plane in which the rotation is taking place, and the sense of the rotation (clockwise or anticlockwise). The key equation is
$$
vecv=vecomegatimesvecr=omegahatntimesvecr
$$

where $vecomega=omegahatn$ is the angular velocity vector
and $times$ is the vector cross product.
Assuming that you know the unit vector $hatn$
pointing in the direction of
$vecomega$,
you can deduce the direction of $vecv$ from the above formula.
Alternatively, you can calculate the magnitude $omega$ from the speed
and the radius of the orbit, and use it together with $hatn$
directly in the above formula.



Of course, if you are prepared to make the approximation that the rotation
is entirely in the $xy$ plane (which is not exactly correct, from your numbers, but quite close) then you know $hatn$ and can easily work out the direction of $vecv$ from $vecr$.






share|cite|improve this answer




















  • Thank you! Silly of me not to think of the direction in which the body rotates.
    – Happy Koala
    2 hours ago










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "363"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fscicomp.stackexchange.com%2fquestions%2f30395%2fcalculate-xyz-velocity-vectors-for-circular-orbit%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










In your code, you seem to be calculating the magnitude $|vecv|$ of the velocity (the speed) from your gravitational formula and multiplying it by the components of the position vector $vecr$. There are two errors here.



  1. You need to multiply the speed by a unit vector in the direction of the velocity, in order to get the velocity vector $vecv$. In general the
    position vector is not a unit vector (actually in this case, it is pretty close, because you chose astronomical units, but that is just luck).

  2. The position vector $vecr$ is pointing in a radial direction, whereas the velocity vector $vecv$ (for circular motion)
    lies in a tangential direction.

You are not actually inputting to your program enough information to work out the direction of the velocity vector. You need to know the plane in which the rotation is taking place, and the sense of the rotation (clockwise or anticlockwise). The key equation is
$$
vecv=vecomegatimesvecr=omegahatntimesvecr
$$

where $vecomega=omegahatn$ is the angular velocity vector
and $times$ is the vector cross product.
Assuming that you know the unit vector $hatn$
pointing in the direction of
$vecomega$,
you can deduce the direction of $vecv$ from the above formula.
Alternatively, you can calculate the magnitude $omega$ from the speed
and the radius of the orbit, and use it together with $hatn$
directly in the above formula.



Of course, if you are prepared to make the approximation that the rotation
is entirely in the $xy$ plane (which is not exactly correct, from your numbers, but quite close) then you know $hatn$ and can easily work out the direction of $vecv$ from $vecr$.






share|cite|improve this answer




















  • Thank you! Silly of me not to think of the direction in which the body rotates.
    – Happy Koala
    2 hours ago














up vote
2
down vote



accepted










In your code, you seem to be calculating the magnitude $|vecv|$ of the velocity (the speed) from your gravitational formula and multiplying it by the components of the position vector $vecr$. There are two errors here.



  1. You need to multiply the speed by a unit vector in the direction of the velocity, in order to get the velocity vector $vecv$. In general the
    position vector is not a unit vector (actually in this case, it is pretty close, because you chose astronomical units, but that is just luck).

  2. The position vector $vecr$ is pointing in a radial direction, whereas the velocity vector $vecv$ (for circular motion)
    lies in a tangential direction.

You are not actually inputting to your program enough information to work out the direction of the velocity vector. You need to know the plane in which the rotation is taking place, and the sense of the rotation (clockwise or anticlockwise). The key equation is
$$
vecv=vecomegatimesvecr=omegahatntimesvecr
$$

where $vecomega=omegahatn$ is the angular velocity vector
and $times$ is the vector cross product.
Assuming that you know the unit vector $hatn$
pointing in the direction of
$vecomega$,
you can deduce the direction of $vecv$ from the above formula.
Alternatively, you can calculate the magnitude $omega$ from the speed
and the radius of the orbit, and use it together with $hatn$
directly in the above formula.



Of course, if you are prepared to make the approximation that the rotation
is entirely in the $xy$ plane (which is not exactly correct, from your numbers, but quite close) then you know $hatn$ and can easily work out the direction of $vecv$ from $vecr$.






share|cite|improve this answer




















  • Thank you! Silly of me not to think of the direction in which the body rotates.
    – Happy Koala
    2 hours ago












up vote
2
down vote



accepted







up vote
2
down vote



accepted






In your code, you seem to be calculating the magnitude $|vecv|$ of the velocity (the speed) from your gravitational formula and multiplying it by the components of the position vector $vecr$. There are two errors here.



  1. You need to multiply the speed by a unit vector in the direction of the velocity, in order to get the velocity vector $vecv$. In general the
    position vector is not a unit vector (actually in this case, it is pretty close, because you chose astronomical units, but that is just luck).

  2. The position vector $vecr$ is pointing in a radial direction, whereas the velocity vector $vecv$ (for circular motion)
    lies in a tangential direction.

You are not actually inputting to your program enough information to work out the direction of the velocity vector. You need to know the plane in which the rotation is taking place, and the sense of the rotation (clockwise or anticlockwise). The key equation is
$$
vecv=vecomegatimesvecr=omegahatntimesvecr
$$

where $vecomega=omegahatn$ is the angular velocity vector
and $times$ is the vector cross product.
Assuming that you know the unit vector $hatn$
pointing in the direction of
$vecomega$,
you can deduce the direction of $vecv$ from the above formula.
Alternatively, you can calculate the magnitude $omega$ from the speed
and the radius of the orbit, and use it together with $hatn$
directly in the above formula.



Of course, if you are prepared to make the approximation that the rotation
is entirely in the $xy$ plane (which is not exactly correct, from your numbers, but quite close) then you know $hatn$ and can easily work out the direction of $vecv$ from $vecr$.






share|cite|improve this answer












In your code, you seem to be calculating the magnitude $|vecv|$ of the velocity (the speed) from your gravitational formula and multiplying it by the components of the position vector $vecr$. There are two errors here.



  1. You need to multiply the speed by a unit vector in the direction of the velocity, in order to get the velocity vector $vecv$. In general the
    position vector is not a unit vector (actually in this case, it is pretty close, because you chose astronomical units, but that is just luck).

  2. The position vector $vecr$ is pointing in a radial direction, whereas the velocity vector $vecv$ (for circular motion)
    lies in a tangential direction.

You are not actually inputting to your program enough information to work out the direction of the velocity vector. You need to know the plane in which the rotation is taking place, and the sense of the rotation (clockwise or anticlockwise). The key equation is
$$
vecv=vecomegatimesvecr=omegahatntimesvecr
$$

where $vecomega=omegahatn$ is the angular velocity vector
and $times$ is the vector cross product.
Assuming that you know the unit vector $hatn$
pointing in the direction of
$vecomega$,
you can deduce the direction of $vecv$ from the above formula.
Alternatively, you can calculate the magnitude $omega$ from the speed
and the radius of the orbit, and use it together with $hatn$
directly in the above formula.



Of course, if you are prepared to make the approximation that the rotation
is entirely in the $xy$ plane (which is not exactly correct, from your numbers, but quite close) then you know $hatn$ and can easily work out the direction of $vecv$ from $vecr$.







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered 2 hours ago









LonelyProf

42116




42116











  • Thank you! Silly of me not to think of the direction in which the body rotates.
    – Happy Koala
    2 hours ago
















  • Thank you! Silly of me not to think of the direction in which the body rotates.
    – Happy Koala
    2 hours ago















Thank you! Silly of me not to think of the direction in which the body rotates.
– Happy Koala
2 hours ago




Thank you! Silly of me not to think of the direction in which the body rotates.
– Happy Koala
2 hours ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fscicomp.stackexchange.com%2fquestions%2f30395%2fcalculate-xyz-velocity-vectors-for-circular-orbit%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery