Clear Filters
Clear Filters

How to use Cartesian coordinates to create Grid Surface?

10 views (last 30 days)
Greetings,
I have been tasked with using Simscape Multibody to investigate contact forces between objects. One step in the Simscape process is to create a Grid Surface, as is described here: https://www.mathworks.com/help/sm/ref/gridsurface.html .
I am provided with CAD files (.stl) and have written a Matlab script that pulls in coordinate points from the STL that describe the shapes I'm interested in. It is simple enough to pull the X and Y values from the STL file and save them as vectors since Grid Surfaces require X and Y to be defined as "Coordinates in the x-direction or y-direction of the grid surface, specified as a real 1-by-m vector".
The Z values, however, are defined as "Elevations of the grid points in the grid surface, specified as a real m-by-n matrix. m and n are the lengths of the vectors for the X Grid Vector and Y Grid Vector parameters."
Does anybody have an idea of how to generate a Z-matrix given cartesian coordinates? I have manually done so with simple shapes, like a cube, but will need to eventually automate the process with a Matlab script.
Thanks

Answers (1)

Torsten
Torsten on 21 Dec 2023
Moved: Torsten on 21 Dec 2023
If the CAD file describes the surface of the body in question, there should be a value for the elevation associated with each (x/y) pair. This is the z-matrix you are asking for.
x = 0:0.05:0.5;
y = 0:0.05:1;
z = x.^2+(y.').^2;
surf(x,y,z)
  1 Comment
Kylen
Kylen on 21 Dec 2023
Thank you for the quick response. I don't know that this will work, unfortunately. The grid surface function in Simscape needs the z matrix itself. Since I'm given x, y, and z as vectors I'm not sure that I can use the surf() command to generate just the z matrix. And since my shapes aren't necessarily described by an equation I can't apply one to calculate z like your example does.
The CAD filetype I'm stuck using, STL, doesn't describe the surface itself. Rather, it takes represents an object's shape by breaking it up into a series of small triangles. The vertices of each triangle come with cartesian coordinates and can be plotted to show the shape of the object in question.
I think that there must be a way to generate the z-matrix that the Simscape grid surface function requires given cartesian coordinates.
The kicker is that Simscape also has a function called Point Cloud, which does use X,Y,Z cartesian coordinates. However, two point clouds cannot interact using Spatial Contact. Point clouds can only interact with grid surfaces, so I have to create a point cloud and a grid surface that represent each object I'm dealing with...

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!