Simulink - How to find the position of the heavy bodies in galaxy simulation and make constraints on 3D position (please?)

조회 수: 2 (최근 30일)
I'm pushing this one again because nobody responded to my previous two questions, so all that is below is old. __________________________________________________________________________________________ In a previous post, I asked
"In the sldemo_eml_galaxy_script default simulink program, it draws a simulation of two galaxies interacting. Is there a way in which I can add another function block which waits until the end of the simulation and then counts how many objects are within a certain volume of the center of a galaxy I choose?"
And the response was
"You may want to find the position of a heavy body, and find all the stars that satisfy your bounding condition. Check 'heavy1' output from "Apply Gravity" block for cores position. For box area example, (x1 < box_width < x2) && (y1 < box_height < y2). You can use logical indexing or find() Since you only want your code to execute at the end of the simulation, you may pass a clock input into your function and do:"
I understand the clock function now, but I still do not understand how to find the position of the bodies or how to count the number of bodies within the constraints. The code under the Apply Gravity block is convoluted to me and I don't see how to grab the position from that.
And if someone could tell me what they meant by "x1,x2,y1,y2" that would be nice to know.
I tried to create a function and I thought it would look something like this but I'm not sure:
function mass = massfromradius(heavy1,light1,clock,simulationtime)
solarmass = 1.9891e+30;
mass = 0;
if clock == simulationtime
% some code to find the position?
for i = 1:n
mat1 = (x1<30000<x2)&&(y1<30000y2)
% something here to find position of light bodies
particles = sum(light(:) == 1);
mass = particles*solarmass+heavy*solarmass
end

채택된 답변

Gaurav Phatnani
Gaurav Phatnani 2018년 2월 1일
I understand that you wish to find the position of all bodies in space so that you can find the number of bodies in a bounding volume.
The signal coming out of the 'combine' block in 'sldemo_eml_galaxy' is of size 700x8. The 700 rows represent the 700 bodies in space, and the eight columns contain the information of the bodies x, y and z position in the 2nd, 3rd and 4th column respectively.
Hence, to sort these bodies your new function would have to take the output of the 'combine' block (GalaxyBodies) and compare their positions to the dimensions of the bounding volume.
function BodiesInBoundary = sortBodies(GalaxyBodies)
bodies_X = GalaxyBodies(701:1400); % x coordinate of all bodies
bodies_Y = GalaxyBodies(1401:2100); % y coordinate of all bodies
bodies_Z = GalaxyBodies(2101:2800); % z coordinate of all bodies
%Insert code to compare these X, Y and Z coordinates to the position and dimensions of the
bounding volume
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by