Question: Unity C#: The script: public class VisualizeWithLineRenderer : MonoBehaviour { [SerializeField] LineRenderer lineRenderer; public int NPoints=5; [Header(Asteroid Parameters)] public float a = 5; public float

Unity C#:

Unity C#: The script: public class VisualizeWithLineRenderer : MonoBehaviour { [SerializeField] LineRenderer

The script:

public class VisualizeWithLineRenderer : MonoBehaviour {

[SerializeField] LineRenderer lineRenderer; public int NPoints=5;

[Header("Asteroid Parameters")] public float a = 5; public float b = 3; ///

/// Add more to this to visualize other functions/schemes /// public enum VisualizationName { None, F_YequalX2, //y=f(x); f(x)=x^2 F_YequalSinX, //y=f(x); f(x)=sin(x) YPequalF_via_Euler_F_2X, //y'=f(x,y); f(x,y)=2*x YPequalF_via_Euler_F_Goose, //y'=f(x,y); f(x,y)=... F_Vequal_Circle, //V=V(t); ...or (x,y,z)=(x(t),y(t),z(t)); F_Vequal_Ellipse, //V=V(t); ...or (x,y,z)=(x(t),y(t),z(t)); asteroid, VPequalF_via_Euler_F_SIR_COVID, //V'=f(t,V) or (x',y',z')=(fx(t,x,y,z),fy(t,x,y,z),fz(t,x,y,z)) VPequalF_via_Euler_F_Lawrence //V'=f(t,V) or (x',y',z')=(fx(t,x,y,z),fy(t,x,y,z),fz(t,x,y,z))

} // Start is called before the first frame update public System.Func F_YequalX2 = x => x*x; public System.Func F_YequalSinX = x => Mathf.Sin(x); public System.Func F_2X = (x, y) => 2 * x; public System.Func F_Circle = (t,r) => new Vector3(r*Mathf.Cos(t),r*Mathf.Sin(t),0); public System.Func F_Ellipse = (t, a, b) => new Vector3(a * Mathf.Cos(t), b * Mathf.Sin(t), 0); //TODO: //public System.Func F_SIR_COVID = (t, a, b) => new Vector3(a * Mathf.Cos(t), b * Mathf.Sin(t), 0);

//TODO: Write the correct expression for the Goose Task: //public System.Func F_YequalGoose = (x,y) => ...;

public VisualizationName visualizationName = VisualizationName.F_YequalX2; void Start() { Vector3 pos = this.transform.position; switch (visualizationName) { case VisualizationName.F_YequalX2: //RenderLine(GetYequalX2(NPoints), Color.green); RenderLine(GetYequalF_X(5, 6, pos.x, pos.y, pos.z,F_YequalX2), Color.green); break; case VisualizationName.YPequalF_via_Euler_F_2X: RenderLine(GetYPequalF_via_Euler(10, 11, pos.x, pos.y, pos.z, F_2X), Color.blue); break; case VisualizationName.F_YequalSinX: RenderLine(GetYequalF_X(Mathf.PI*2,NPoints, pos.x, pos.y, pos.z, F_YequalSinX), Color.yellow); break; case VisualizationName.YPequalF_via_Euler_F_Goose: //TODO: Fill in the data for the Goose Task //you need to use the parameters a,w,b when declaring F // //int L=...; //int NPoints=...; //float x0=...; //float y0=...; //float z0=...; //Func F=...; //Color color=...; // //TODO: Once you have the above data right, uncomment this line // //RenderLine(GetYPequalF_via_Euler(L, NPoints, x0, y0, z0, F), color); break; case VisualizationName.F_Vequal_Ellipse: RenderLine(GetVequalF_T(Mathf.PI * 2, NPoints, pos.x, pos.y, pos.z, F_Ellipse), Color.magenta);

break; default: print("No visualization exists for this choice!"); break;

}

} ///

/// Used to visualize an array of points in 3D given as vectors. /// Uses the LineRenderer component. /// For now some configuration parameters are hardcoded (startWidth etc). /// Some others are left at their default values. /// If you need a more sofisticated rendering, create an overload /// whereby you pass a configuration dictionary. /// /// /// void RenderLine(Vector3[] points, Color color) { lineRenderer = GetComponent(); lineRenderer.positionCount = points.Length; lineRenderer.startWidth = 0.2f; //hardcoded; lineRenderer.endWidth = 0.2f; //hardcoded; lineRenderer.startColor = color; lineRenderer.endColor = color; for (int i = 0; i

} ///

/// Hardcoded function; obsolete; use GetYequalF_X instead /// /// /// /// Vector3[] GetYequalX2(int NPoints) { Vector3[] result = new Vector3[NPoints]; for(int i = 0; i /// Can be used to Visualize functions of type y=f(x) (or x=x(t), y=y(t) etc) /// /// Length of interval [x0,x0+L] /// Number of points /// /// /// /// The function to visualize /// Vector3[] GetYequalF_X(float L, int NPoints, float X0, float Y0, float Z0, System.Func F) { float H = System.Convert.ToSingle(L) / (NPoints - 1); Vector3[] result = new Vector3[NPoints]; result[0].x = X0; result[0].y = Y0; result[0].z = Z0;

for (int i = 1; i /// Can be used to visualize the function y you get from Euler Scheme /// that satisfies y'=f(x,y) with initial conditions y(x0)=y0 /// /// /// /// /// /// /// The function F in y'=F(x,y) /// Vector3[] GetYPequalF_via_Euler(float L, int NPoints, float X0, float Y0, float Z0, System.Func F) { //y'=f(x,y) //y0=y(x0) float H = System.Convert.ToSingle(L) / (NPoints - 1); Vector3[] result = new Vector3[NPoints]; result[0].x = X0; result[0].y = Y0; result[0].z = Z0;

for (int i = 1; i /// Visualization of V'=Vf(t,a,b); //( /// /// /// /// /// /// /// /// Vector3[] GetVequalF_T(float L, int NPoints, float X0, float Y0, float Z0, System.Func F) { float H = System.Convert.ToSingle(L) / (NPoints - 1); Vector3[] result = new Vector3[NPoints]; result[0].x = X0; result[0].y = Y0; result[0].z = Z0; //result[0].x = a; //result[0].y = 0; //result[0].z = 0; float angle=0; // = result[i - 1].x; //, y = Y0+F(x);

for (int i = 1; i

}

Use Euler Method to simulate the movement of the goose towards its roost under windy conditions. It is assumed that the goose always tries to head towards its roost (east to west) with constant speed b, but under the influence of the northerly wind of speed W the actual direction is as in the figures below. w (x(t), y(t)) y(t) X(t) (0,0) Ala, 0) Wind Denoting with (x(t),y(t)) the position of the goose at time t (NB this is the horizontal projection of the position; we are ignoring the vertical movement here), the ODE to determine the trajectory y=y(x) as given by: 1 dy dx b* y-W* (x2 + y2) rate_of_change_of_y_with_x = = b* X With initial condition yo = y(xo) = y(a) = 0 (that is xo=a) . Using the Euler Method in Unity from class work, create a simulation for the goose movement with simulation parameters a, b, and w (20%). . Create graphs for at least the following data (15%): Use Euler Method to simulate the movement of the goose towards its roost under windy conditions. It is assumed that the goose always tries to head towards its roost (east to west) with constant speed b, but under the influence of the northerly wind of speed W the actual direction is as in the figures below. w (x(t), y(t)) y(t) X(t) (0,0) Ala, 0) Wind Denoting with (x(t),y(t)) the position of the goose at time t (NB this is the horizontal projection of the position; we are ignoring the vertical movement here), the ODE to determine the trajectory y=y(x) as given by: 1 dy dx b* y-W* (x2 + y2) rate_of_change_of_y_with_x = = b* X With initial condition yo = y(xo) = y(a) = 0 (that is xo=a) . Using the Euler Method in Unity from class work, create a simulation for the goose movement with simulation parameters a, b, and w (20%). . Create graphs for at least the following data (15%)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!