Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

OK so I want to create a simple physics program that I just can not figure out.

ID: 3582837 • Letter: O

Question

OK so I want to create a simple physics program that I just can not figure out. I have copied and pasted what I have so far. I have included comments in there. I am following a book which contains the pseudo for all this. Having a hard time putting it in code. Thank you in advance!

using PhysicsClass;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PhysicsClass
{
class Program
{

public struct Vector3
{
}

public struct Vector2
{
}

public struct BoundingSphere
{
public Vector3 center;
public Vector3 centerVector;
}

public struct Raycast
{

public Vector3 startPoint, endPoint;

}

public struct Plane
{
}
public struct AABB2D
{
}

public struct AABB2d
{
}

public struct LSPlanereturn
{
public bool intersects;
}
//variables
//which library do i need to be using to be able to use the Vector 2 and 3 variables
Vector3 normal, startPoint, endPoint, center, point, acceleration, velocity, position;
Vector2 min, max;
//also which library is it for this one
BoundingSphere a, b;
float d, radius, mass;
bool intersects;

//struct method to be able to find the radius between the start and end points
struct Capsule2D
{
Vector2 startPoint, endPoint;
float radius;
}

/// <summary>
/// Sphere versus Sphere Intersection
/// </summary>
/// <returns></returns>
public bool SphereIntersection(BoundingSphere a, BoundingSphere b)
{

//how do i get the body of this method to work
//i need a little help with my raycast coding
//Vector3 centerVector = (a.center) - (b.center);
//float distSquared = DotProduct(centerVector, centerVector)
//if distSquared < ((a.radius + b.radius) * (a.radius + b.radius))
return true;
//else
//return false;
}

private object DotProduct(Vector3 centerVector1, Vector3 centerVector2)
{
throw new NotImplementedException();
}

//AABB versus AABB intersection
public bool AABBIntersection(AABB2D a, AABB2d b)
{

//bool test = (a.max.x < b.min.x) || (b.max.x < a.min.x) ||
//(a.max.x < b.min.x) || (b.max.x < a.min.x)
//return !test;
return true;
}


public void LSPlaneIntersection(Raycast r, Plane p)
{
LSPlanereturn retVal;
retVal.intersects = false;
//Vector3 v = r.endPoint - r.startPoint;
float vDotn;// = DotProduct(v, p.normal)
//if (vDotn == 0)
//{

//t = -1 * (DotProduct(r.startPoint, p.normal) + p.d)
//t /= vDotn;

//}

//if (t >= 0 && t <= 1)

//{

retVal.intersects = true;
//retVal.point = r.startPoint + t * v;

//}
//return retVal;
}

public void PointinPolygon(Vector3[] verts, int numSides, Vector3 point)

{
Vector3 normal;// = CrossProduct(Vector3[1] - verts[0], Vector3[2] - verts[1]

//normal.Normalize()
Vector3 side, to, cross;
for (int i = 1; i < numSides; i++)
{
//side = verts[1] - verts[i - 1];
//to = point - verts[i - 1];
//cross = CrossProduct( sides, to );
//cross.Normalize;

}

//if (DotProduct(cross, normal))
//{

//return false;

//}

//side = verts[0] - verts[numSides - 1]
//to = point - verts[numSides - 1]
//cross = CrossProduct(sides. to)
//cross.Normalize

//if(DotProduct(cross, normal) < 0)
//{
//return false;

//}

//return true;
}

public void SweptSphere(BoundingSphere p0, BoundingSphere q0, BoundingSphere p1, BoundingSphere q1)
{
//Vector3 vp = p1.center - p0.center;
//Vector3 vq = q1.center - q0.center;
//Vector3 A = p0.center - q0.center;
//Vector3 B = vp -vq;


//float a = DotProduct(B, B)
//float b = 2 * DotProduct(A, B)
//float c = DotProduct(A, A) - ((q0.radius + p0.radius) * (q0.radius + p0..radius))

//float disc = b * b - 4 * a * c;

//if (disc >= 0)

//{

//return true;
//}

//else
//{

//return false;

//}
}

public void Update(float DeltaTime)
{
//Vector3 sumOfForces;
//acceleration = sumOfForces / mass

//Eulers integration form
//position += velocity * DeltaTime;
//velocity += accelartion * DeltaTime;

}
static void Main(string[] args)
{

}
}

}

Explanation / Answer

Please find below your modified program :

using PhysicsClass;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PhysicsClass
{
class Program
{

public struct Vector3
{
}

public struct Vector2
{
}

public struct BoundingSphere
{
public Vector3 center;
public Vector3 centerVector;
}

public struct Raycast
{

public Vector3 startPoint, endPoint;

}

public struct Plane
{
}
public struct AABB2D
{
}

public struct AABB2d
{
}

public struct LSPlanereturn
{
public bool intersects;
}
//variables
//which library do i need to be using to be able to use the Vector 2 and 3 variables
Vector3 normal, startPoint, endPoint, center, point, acceleration, velocity, position;
Vector2 min, max;
//also which library is it for this one
BoundingSphere a, b;
float d, radius, mass;
bool intersects;

//struct method to be able to find the radius between the start and end points
struct Capsule2D
{
Vector2 startPoint, endPoint;
float radius;
}

/// <summary>
/// Sphere versus Sphere Intersection
/// </summary>
/// <returns></returns>
public bool SphereIntersection(BoundingSphere a, BoundingSphere b)
{

function SphereIntersection(BoundingSphere a, BoundingSphere b)

   // To construct a vector between centers, and get length squared

   Vector3 centerVector = b.center - a.center

   // To recall that the length squared of v is the same as v dot v

   float distSquared = DotProduct(centerVector, centerVector)

   // Is distSquared < sum of radii squared?

   if distSquared < ((a.radius + b.radius) * (a.radius + b.radius))

      return true

   else

      return false

   end

end
}

private object DotProduct(Vector3 centerVector1, Vector3 centerVector2)
{
throw new NotImplementedException();
}

//AABB versus AABB intersection
public bool AABBIntersection(AABB2D a, AABB2d b)
{

bool test = (a.max.x < b.min.x) || (b.max.x < a.min.x) ||
               (a.max.y < b.min.y) || (b.max.y < a.min.y)

   return !test
return true;
}


// Return value is this struct

struct LSPlaneReturn

bool intersects

Vector3 point

function LSPlaneIntersection( RayCast r, Plane p )

LSPlaneReturn retVal

retVal. intersects = false

// Calculate v in parametric line segment equation

Vector3 v = r. endPoint – r. startPoint

// Check if the line segment is parallel to the plane

float vDotn = DotProduct( v, p. normal )

if vDotn is not approximately 0

t = -1 * (DotProduct( r. startPoint, p. normal) + p. d )

t /= vDotn

// t should be between startPoint and endPoint (0 to 1)

if t >= 0 && t <= 1

retVal. intersects = true

// Calculate the point of intersection

retVal. point = r. startPoint + v * t

end

else

// Test if r.startPoint is on the plane

...

end

return retVal


}

function PointInPolygon(Vector3[] verts, int numSides,
                        Vector3 point)
   // Calculate the normal of the polygon
   Vector3 normal = CrossProduct(Vector3(verts[1] – verts[0]),
                                 Vector3(verts[2] – verts[1])
   normal.Normalize()

   // Temporary variables
   Vector3 side, to, cross

   for int i = 1, i < numSides, i++
      // FROM previous vertex TO current vertex
      side = verts[i] - verts[i – 1]
      // FROM previous vertex TO point
      to = pointverts[i – 1]

      cross = CrossProduct(side, to)
      cross.Normalize()

      // This means it's outside the polygon
      if DotProduct(cross, normal) < 0
         return false
      end
   loop

   // Have to test the last side, which is from last vertex to first
   side = verts[0] – verts[numSides – 1]
   to = pointverts[numSides – 1]
   cross = CrossProduct(side, to)
   cross.Normalize()

   if DotProduct(cross, normal) < 0
      return false
   end

   // We're inside all sides
   return true
end

}

public void SweptSphere(BoundingSphere p0, BoundingSphere q0, BoundingSphere p1, BoundingSphere q1)
{
//Vector3 vp = p1.center - p0.center;
//Vector3 vq = q1.center - q0.center;
//Vector3 A = p0.center - q0.center;
//Vector3 B = vp -vq;


//float a = DotProduct(B, B)
//float b = 2 * DotProduct(A, B)
//float c = DotProduct(A, A) - ((q0.radius + p0.radius) * (q0.radius + p0..radius))

//float disc = b * b - 4 * a * c;

//if (disc >= 0)

//{

//return true;
//}

//else
//{

//return false;

//}
}

public void Update(float DeltaTime)
{
//Vector3 sumOfForces;
//acceleration = sumOfForces / mass

//Eulers integration form
//position += velocity * DeltaTime;
//velocity += accelartion * DeltaTime;

}
static void Main(string[] args)
{

}
}

}