Generate the motion (Trajectory) of a sphere (or point) with given ... (2024)

64 views (last 30 days)

Show older comments

Alberto Acri on 21 Aug 2024 at 11:27

  • Link

    Direct link to this question

    https://webchat.mathworks.com/matlabcentral/answers/2146869-generate-the-motion-trajectory-of-a-sphere-or-point-with-given-velocity-value

  • Link

    Direct link to this question

    https://webchat.mathworks.com/matlabcentral/answers/2146869-generate-the-motion-trajectory-of-a-sphere-or-point-with-given-velocity-value

Answered: Madheswaran on 23 Aug 2024 at 5:51

  • DATA.mat

Open in MATLAB Online

Hi. I have this file 'DATA'. The first 3 columns are the nodes in space (X,Y,Z in [m]). The 4th column is not of interest. The fifth column is the velocity in [m/s].

Is it possible to visualize the motion (green direction) of a sphere (e.g., the red one in the figure) moving following the velocity values in the fifth column of DATA?

load("DATA.mat");

figure

plot3(DATA(:,1),DATA(:,2),DATA(:,3),'-k','LineWidth',0.1);

hold on

plot3(DATA(1,1),DATA(1,2),DATA(1,3),'r.','MarkerSize',30);

hold off

axis equal

xlabel('x')

ylabel('y')

zlabel('z')

grid off

Generate the motion (Trajectory) of a sphere (or point) with given ... (2)

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Answers (2)

Aquatris on 21 Aug 2024 at 12:04

  • Link

    Direct link to this answer

    https://webchat.mathworks.com/matlabcentral/answers/2146869-generate-the-motion-trajectory-of-a-sphere-or-point-with-given-velocity-value#answer_1502694

  • Link

    Direct link to this answer

    https://webchat.mathworks.com/matlabcentral/answers/2146869-generate-the-motion-trajectory-of-a-sphere-or-point-with-given-velocity-value#answer_1502694

Edited: Aquatris on 21 Aug 2024 at 12:09

  • data.mat

If you dont care about the actual timing and things, here is one way where the colors of the path indicate the speed and a simple animation show the full motion:

load('data.mat')

x = [DATA(:,1);nan];

y = [DATA(:,2);nan];

z = [DATA(:,3);nan];

v = [DATA(:,5);nan];

l = length(x);

figure(1)

for i = 1:1 % change it to 1:l to animate

clf

colormap(winter)

patch(x,y,z,v,'Facecolor','none','EdgeColor','interp')

colorbar

view(150,15)

grid on

grid minor

hold on

plot3(x(i),y(i),z(i),'ro','MarkerSize',15)

hold off

pause(0.1)

end

Generate the motion (Trajectory) of a sphere (or point) with given ... (4)

2 Comments

Show NoneHide None

Alberto Acri on 21 Aug 2024 at 13:11

Direct link to this comment

https://webchat.mathworks.com/matlabcentral/answers/2146869-generate-the-motion-trajectory-of-a-sphere-or-point-with-given-velocity-value#comment_3242809

  • Link

    Direct link to this comment

    https://webchat.mathworks.com/matlabcentral/answers/2146869-generate-the-motion-trajectory-of-a-sphere-or-point-with-given-velocity-value#comment_3242809

Open in MATLAB Online

  • newData_SEL_cell.mat

Thank you. It might be helpful. If I would like to display multiple 'DATA' matrices present in a cell 'newData_SEL_cell' how can I display the trends simultaneously in the same figure?

I've tried a for loop but it doesn't seem to work the way it's supposed to. Suggestion?

load('newData_SEL_cell.mat')

figure

for S = 1:height(newData_SEL_cell)

DATA = newData_SEL_cell(S,1); % 1 e 50

DATA = cell2mat(DATA);

x = [DATA(:,1);nan];

y = [DATA(:,2);nan];

z = [DATA(:,3);nan];

v = [DATA(:,5);nan];

l = length(x);

%figure

for i = 1:l % change it to 1:l to animate

clf

colormap(winter)

patch(x,y,z,v,'Facecolor','none','EdgeColor','interp')

colorbar

view(150,15)

grid off

%grid minor

hold on

plot3(x(i),y(i),z(i),'ko','MarkerSize',2)

plot3(x(i),y(i),z(i),'ko','MarkerSize',1)

plot3(x(i),y(i),z(i),'ko','MarkerSize',3)

hold off

axis equal

pause(0.1)

end

end

Aquatris on 21 Aug 2024 at 13:49

Direct link to this comment

https://webchat.mathworks.com/matlabcentral/answers/2146869-generate-the-motion-trajectory-of-a-sphere-or-point-with-given-velocity-value#comment_3242834

  • Link

    Direct link to this comment

    https://webchat.mathworks.com/matlabcentral/answers/2146869-generate-the-motion-trajectory-of-a-sphere-or-point-with-given-velocity-value#comment_3242834

Edited: Aquatris on 21 Aug 2024 at 13:58

Open in MATLAB Online

  • newData_SEL_cell.mat

Assuming each row happens at the same time:

load('newData_SEL_cell.mat')

% get x,y,z,v as cell arrays

x = cellfun(@(x) {[x(:,1);nan]},newData_SEL_cell);

y = cellfun(@(x) {[x(:,2);nan]},newData_SEL_cell);

z = cellfun(@(x) {[x(:,3);nan]},newData_SEL_cell);

v = cellfun(@(x) {[x(:,5);nan]},newData_SEL_cell);

% maximum number of data points in the whole data set

L = max(cellfun(@(A) length(A),x));

figure(1)

% loop through data points

for i = 1:1 % change it to 1:(L-1) to animate

clf

for j = 1:length(x) % loop through data sets

colormap(winter)

patch(x{j},y{j},z{j},v{j},'Facecolor','none','EdgeColor','interp')

colorbar

view(150,15)

grid on

grid minor

hold on

% because the 3 datasets are not the same length we need to check

if (length(x{j}) >= i) % check if we are not at the end point

plot3(x{j}(i),y{j}(i),z{j}(i),'ro','MarkerSize',15)

else

% (end-1) cause last element we put a 'nan' to prevent unnecessary

% connection between last point and first point during 'patch'

plot3(x{j}(end-1),y{j}(end-1),z{j}(end-1),'ro','MarkerSize',15)

end

end

hold off

pause(0.1)

end

Generate the motion (Trajectory) of a sphere (or point) with given ... (7)

Sign in to comment.

Madheswaran on 23 Aug 2024 at 5:51

  • Link

    Direct link to this answer

    https://webchat.mathworks.com/matlabcentral/answers/2146869-generate-the-motion-trajectory-of-a-sphere-or-point-with-given-velocity-value#answer_1503904

  • Link

    Direct link to this answer

    https://webchat.mathworks.com/matlabcentral/answers/2146869-generate-the-motion-trajectory-of-a-sphere-or-point-with-given-velocity-value#answer_1503904

Open in MATLAB Online

Hello,

The data appears somewhat unclear, as it specifies the object's velocity only at certain spatial positions, necessitating some assumptions. Here is the assumption made regarding the object's velocity in the intermediate position between the position mentioned in any two rows:

For the space between DATA(i, 1:3) and DATA(i+1, 1:3), the object is assumed to moving at a constant velocity as described in DATA(i, 5).

Below is a simple script to visualize the object's movement using a loop:

load DATA.mat

figure

plot3(DATA(:, 1), DATA(:, 2), DATA(:, 3));

% changing the aspect ratio and view to get the similar view as the posted image

pbaspect([1 1 4])

view([154.8 19.8])

ln = size(DATA, 1);

time_unit_divisor = 10;

hold on

pt = plot3(DATA(1, 1), DATA(1, 2), DATA(1, 3), 'r.', 'MarkerSize',30);

for i = 2:ln

distance = norm(DATA(i, 1:3) - DATA(i-1, 1:3));

velocity = DATA(i-1, 5);

time_taken = distance/velocity;

adjusted_time = time_taken/time_unit_divisor;

pause(adjusted_time);

%update the new position

pt.XData = DATA(i, 1);

pt.YData = DATA(i, 2);

pt.ZData = DATA(i, 3);

end

hold off

The above code would produce the plot like this:

Generate the motion (Trajectory) of a sphere (or point) with given ... (9)

You can adjust the speed of the animation by modifying the ‘time_unit_divisor’ variable. To enhance the smoothness of the animation, consider plotting additional points within each iteration by interpolating the intermediate positions of the object.

Hope this answers your question!

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D PlotsAnimation

Find more on Animation in Help Center and File Exchange

Tags

  • motion
  • trajectory

Products

  • MATLAB

Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Generate the motion (Trajectory) of a sphere (or point) with given ... (10)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

Generate the motion (Trajectory) of a sphere (or point) with given ... (2024)

FAQs

What is the formula for trajectory motion? ›

What is the equation of parabolic trajectory of a projectile? (θ= angle between the projectile motion and the horizontal) y=x2tanθ−gx2u2cos2θ

How to calculate the trajectory of a ball? ›

To find the trajectory of a projectile, use the parametric equations for horizontal (x) and vertical (y) positions: x = vₒₓt and y = vₒᵧt - 0.5gt². Here, vₒₓ and vₒᵧ are the initial horizontal and vertical velocities, g is the acceleration due to gravity, and t is the time elapsed.

How do you find trajectory motion? ›

Answer: Hence the equation of the trajectory of the projectile is y = x√3 - 0.544x2. Example 2: If Trevor hits a ball with his bat at an initial velocity of 45 m/s in the air. In the ball's direction of travel, the end of the field is 140.0 m away. If the initial angle at which the ball is thrown is 66.4°.

How do you describe the trajectory of a projectile answer? ›

The trajectory of a projectile is a parabola. Projectile motion is a form of motion where an object moves in a bilaterally symmetrical, parabolic path. The path that the object follows is called its trajectory.

What is the simple equation of trajectory? ›

Y=xtanθ−g×x22u2cos2θ is called equation of trajectory. Derive the equations of projectile motion. A projectile is given an initial velocity of ^i+2^j. The cartesian equation of its path is (g=10 ms−2).

What is the equation of point trajectory? ›

The equation of trajectory of a projectile thrown from a point on the ground is y=(x−x240)m. If g=10ms−2 The maximum height reached is. Step by step video & image solution for The equation of trajectory of a projectile thrown from a point on the ground is y=(x-x^(2)/40)m.

What is the equation for projectile motion? ›

R=v02sin2θ0g R = v 0 2 sin ⁡ 2 θ 0 g , where v0 is the initial speed and θ0 is the initial angle relative to the horizontal. The proof of this equation is left as an end-of-chapter problem (hints are given), but it does fit the major features of projectile range as described.

What is the formula for horizontal trajectory? ›

(b) The equation that describes the horizontal motion is x=x0+vxt. x = x 0 + v x t . With x0=0, x 0 = 0 , this equation becomes x=vxt.

What is the equation of trajectory of a projectile thrown on the ground? ›

The equation of traiectory of a projectile thrown Trom a level ground near the surface of earth is given by y = ax – bx2 with y axis in vertical direction and x-axis in horizontal direction, a and b are constants.

What is the equation for the trajectory of circular motion? ›

An object executing uniform circular motion can be described with equations of motion. The position vector of the object is →r(t)=Acosωt^i+Asinωt^j, r → ( t ) = A cos ω t i ^ + A sin ω t j ^ , where A is the magnitude |→r(t)|, | r → ( t ) | , which is also the radius of the circle, and ω is the angular frequency.

How can trajectories be determined? ›

The trajectory is determined by the object's vertical (y) and horizontal (x) position components. When a projectile is launched with an initial velocity v0 at an angle θ from the horizontal plane, the vertical position of the object in terms of its horizontal position can be determined using this formula.

How do you prove the trajectory equation? ›

Here, is the angle of trajectory and is the displacement in x direction. Here, is the gravitational acceleration and is the displacement in y direction. Thus, the equation of trajectory is y = x tan ⁡ θ − g x 2 2 u 2 cos 2 θ .

What is the trajectory formula? ›

Trajectory formula

The horizontal velocity component V x V_x Vx is equal to V 0 × cos ⁡ V0×cos(α). The vertical velocity component V y = V 0 × sin ⁡ ( α ) V_y= V_0\times \sin(\alpha) Vy=V0×sin(α).

What is the trajectory of a ball? ›

BASIC PHYSICS OF BALL TRAJECTORIES

When a ball or any other object is projected through the air it will follow a curved trajectory until it hits the ground. The trajectory can be calculated easily if we ignore air resistance and assume that the only force acting on the ball is that due to gravity.

How do you calculate flight trajectory? ›

An object launched horizontally at a height H travels a range v0√2Hg during a time of flight T=√2Hg. Projectile motion is a form of motion where an object moves in a parabolic path. The path followed by the object is called its trajectory.

What is the projectile motion formula? ›

h=v20y2g. h = v 0 y 2 2 g . This equation defines the maximum height of a projectile above its launch position and it depends only on the vertical component of the initial velocity. Check Your Understanding A rock is thrown horizontally off a cliff 100.0m high with a velocity of 15.0 m/s.

What is the formula for trajectory analysis? ›

One common trajectory formula is the parametric equation: (x(t)=v₀cos(θ)t, y(t)=v₀sin(θ)t−(1/2)gt²), where v₀ is the initial velocity, θ is the launch angle, t is time, g is acceleration due to gravity, and x(t) and y(t) represent horizontal and vertical positions, respectively.

What is the formula for range of trajectory? ›

Step 2: Identify the angle at which a projectile is launched. The projectile is launched at the angle of θ = 30 ∘ . Step 3: Find the range of a projectile by substituting the initial velocity and the angle found in steps 1 and 2 into the equation R = v 0 2 g sin ⁡ .

References

Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 5479

Rating: 4.1 / 5 (62 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.