Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Projectile at an Angle
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/wb/ (C) Ken Webb Mon Feb 13 2012 14:19:17 GMT-0500 (EST)-->
<XholonWorkbook>
<Notes><![CDATA[
Khan Academy
------------
Title: Projectile at an Angle
Description: Figuring out the horizontal displacement for a projectile launched at an angle
Url: http://www.khanacademy.org/video/projectile-at-an-angle?playlist=Physics
InternalName: projectile-at-an-angle
YoutubeId: ZZ39o1rAZWY
Keywords: physics, projectile, component, launch, motion
My Notes
--------
As an example, you can change angleDegrees to any value between 0 and 360.
And/or change the initial velocity (vInitial) to 5 or 20 or whatever.
Pretend you're on the Moon where g has a value of -1.6 .
]]></Notes>
<script implName="lang:python:inline:"><![CDATA[
import math
g = -9.80665 # acceleration due to gravity
vInitial = 10 # 10 m/s
angleDegrees = 30
angleRadians = angleDegrees * (math.pi / 180)
vInitialX = vInitial * math.cos(angleRadians)
vInitialY = vInitial * math.sin(angleRadians)
vFinalY = vInitialY * -1
vDeltaY = vFinalY - vInitialY
tDelta = vDeltaY / g
sX = vInitialX * tDelta
print "sX = " str(sX) " m"
#http://ideone.com/7bJoa
# result: sX = 8.8310014509 m
]]></script>
<script implName="lang:javascript:inline:"><![CDATA[
var g = -9.80665; // acceleration due to gravity
var vInitial = 10; // 10 m/s
var angleDegrees = 30;
var angleRadians = angleDegrees * (Math.PI / 180);
var vInitialX = vInitial * Math.cos(angleRadians);
var vInitialY = vInitial * Math.sin(angleRadians);
var vFinalY = vInitialY * -1;
var vDeltaY = vFinalY - vInitialY;
var tDelta = vDeltaY / g;
var sX = vInitialX * tDelta;
print("sX = " sX " m\n");
//javascript:(function(vInitial,angleDegrees){var g=-9.80665;var angleRadians=angleDegrees*(Math.PI/180);var vInitialX=vInitial*Math.cos(angleRadians);var vInitialY=vInitial*Math.sin(angleRadians);var vFinalY=vInitialY*-1;var vDeltaY=vFinalY-vInitialY;var tDelta=vDeltaY/g;var sX=vInitialX*tDelta;alert("sX = " sX " m\n");})(10,30)
]]></script>
<_-.XholonClass>
<!-- domain objects -->
<PhysicalSystem/>
<Cannon/>
<Projectile/>
<!-- collections of domain objects -->
<Projectiles/>
<!-- quantities -->
<Displacement superClass="Length"/>
<ProjectileVelocity superClass="Velocity"/>
</_-.XholonClass>
<xholonClassDetails>
<Cannon>
<port name="degrees" connector="#xpointer(Angle[1])"/>
<port name="radians" connector="#xpointer(Angle[2])"/>
<port name="projectileVelocity" connector="#xpointer(ProjectileVelocity)"/>
<port name="projectiles" connector="#xpointer(../Projectiles)"/>
</Cannon>
<Projectile>
<port name="accelerationDueToGravity" connector="#xpointer(../../AccelerationDueToGravity)"/>
<port name="velocity" connector="#xpointer(Velocity)"/>
<port name="duration" connector="#xpointer(Duration)"/>
<port name="displacement" connector="#xpointer(Displacement)"/>
</Projectile>
</xholonClassDetails>
<PhysicalSystem>
<Cannon>
<Angle>30 °</Angle>
<Angle>0.0 rad</Angle>
<ProjectileVelocity>10.0 m/s</ProjectileVelocity>
</Cannon>
<Projectiles>
<Projectile roleName="rock">
<Velocity>0.0 0.0 m/s</Velocity>
<Duration>0.0 s</Duration>
<Displacement>0.0 0.0 m</Displacement>
</Projectile>
</Projectiles>
<AccelerationDueToGravity/>
</PhysicalSystem>
<Cannonbehavior implName="lang:python:inline:"><![CDATA[
# Step 1: Insert this Python script as the last child of Cannon.
import math
deg = degrees.val_Object
rad = radians.val_Object
rad = deg.to(rad.unit)
radians.setVal(rad)
v = projectileVelocity.val
vX = v * math.cos(radians.val)
vY = v * math.sin(radians.val)
velocityStr = " " str(vX) " " str(vY) " m/s"
projectile = projectiles.firstChild
while projectile != None:
projectile.findFirstChildWithXhClass("Velocity").setVal(velocityStr)
projectile = projectile.nextSibling
]]></Cannonbehavior>
<Projectilebehavior implName="lang:python:inline:"><![CDATA[
# Step 2: Insert this Python script as the last child of Projectile.
vInitial = velocity.values
vInitialX = vInitial[0]
vInitialY = vInitial[1]
vFinalY = vInitialY * -1.0
vDeltaY = vFinalY - vInitialY
duration.setVal(vDeltaY / (accelerationDueToGravity.val * -1.0))
displacement.setVal("" str(vInitialX * duration.val) " 0.0 m")
print "sX = " str(displacement.val) " m"
]]></Projectilebehavior>
<Cannonbehavior implName="lang:javascript:inline:"><![CDATA[
// Step 1: Insert this JavaScript script as the last child of Cannon.
var deg = degrees.val_Object;
var rad = radians.val_Object;
var rad = deg.to(rad.unit);
radians.setVal(rad);
var v = projectileVelocity.val;
var vX = v * Math.cos(radians.val);
var vY = v * Math.sin(radians.val);
var velocityStr = " " vX " " vY " m/s";
var projectile = projectiles.firstChild;
while (projectile != null) {
projectile.findFirstChildWithXhClass("Velocity").setVal(velocityStr);
projectile = projectile.nextSibling;
}
]]></Cannonbehavior>
<Projectilebehavior implName="lang:javascript:inline:"><![CDATA[
// Step 2: Insert this JavaScript script as the last child of Projectile.
var vInitial = velocity.values;
var vInitialX = vInitial[0];
var vInitialY = vInitial[1];
var vFinalY = vInitialY * -1.0;
var vDeltaY = vFinalY - vInitialY;
duration.setVal(vDeltaY / (accelerationDueToGravity.val * -1.0));
displacement.setVal("" (vInitialX * duration.val) " 0.0 m");
print("sX = " displacement.val " m\n");
]]></Projectilebehavior>
<script implName="lang:BrowserJS:inline:"><![CDATA[
// this script can be used with the Bestiary applet; it writes to a div element in the web page
(function(vInitial,angleDegrees){var g=-9.80665;var angleRadians=angleDegrees*(Math.PI/180);var vInitialX=vInitial*Math.cos(angleRadians);var vInitialY=vInitial*Math.sin(angleRadians);var vFinalY=vInitialY*-1;var vDeltaY=vFinalY-vInitialY;var tDelta=vDeltaY/g;var sX=vInitialX*tDelta;document.getElementById('usercontent').innerHTML = "sX = " sX " m\n";})(10,45)
]]></script>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg xml,
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment