Getting xyz coordinates for a specific point on stl cad model

29 visualizzazioni (ultimi 30 giorni)
In my project i need to create a path for welding robot. First step is by selecting the welding space by selecting a set of xyz points. i have tried the buttondownfcn, but it represent the point on a plane not on the 3d object. i need to be able to select points from the stl model on th object itself to create the path or to highlight it.also, i have tried alot iof functions but i don't know how to do it.
if anyone could help me i would be grateful.
thanks.
  2 Commenti
Rik
Rik il 14 Dic 2022
Each face is defined by vertices, which each are defined by xyz coordinates. So finding the coordinates of a corner is as simple as an indexing operation. What exactly did you try to solve this part of the problem?
Askic V
Askic V il 18 Gen 2023
If you have stl model in ascii and if you open that file in txt editor, you can see something like this:
facet normal 0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex -5.000000e+01 -5.000000e+01 6.000000e+02
vertex 5.000000e+01 -5.000000e+01 6.000000e+02
vertex -5.000000e+01 5.000000e+01 6.000000e+02
endloop
endfacet
facet normal -0.000000e+00 0.000000e+00 1.000000e+00
outer loop
vertex -5.000000e+01 5.000000e+01 6.000000e+02
vertex 5.000000e+01 -5.000000e+01 6.000000e+02
vertex 5.000000e+01 5.000000e+01 6.000000e+02
endloop
endfacet
Just as Rik said, verices are defined by xyz coordinates. So, there are only a finite number of points and its coordinates that are saved in the stl file. I guess what you're trying to do is to click anywhere on the object and get its 3D coordinates, but standard Matlab functionality can return only coordinates that are already saved and necessary to create stl object.
You can look at this, but I'm not sure if that will help you:
Good luck.

Accedi per commentare.

Risposte (1)

Nithin Kumar
Nithin Kumar il 4 Set 2023
Hi Ahmed,
I understand that you want to know the process of generating XYZ coordinates for a specific point on an STL CAD model in MATLAB. To get XYZ coordinates, kindly refer to the following steps:
1. Load the STL file: Use the "stlread" function in MATLAB to import the STL file into your workspace. This function reads the vertices and faces of the 3D model.
[vertices, faces] = stlread('your_model.stl');
2. Identify the specific point: Determine the coordinates of the point you are interested in, either by its index in the vertices array or by specifying its XYZ coordinates.
3. Access the coordinates: Once you know the index or coordinates of the point, you can access its XYZ coordinates from the `vertices` array.
In case you have the index of the point, kindly refer to the following code snippet -
pointIndex = 42; % Replace with the actual index of your point
xyzCoordinates = vertices(pointIndex, :);
In case you have the XYZ coordinates of the point which you want to find, kindly refer to the following code snippet -
desiredCoordinates = [x, y, z]; % Replace with the actual coordinates
% Find the closest point in the vertices array
distances = sqrt(sum((vertices - desiredCoordinates).^2, 2));
[minDistance, pointIndex] = min(distances);
xyzCoordinates = vertices(pointIndex, :);
Now, the "xyzCoordinates" variable will contain the XYZ coordinates of the specific point on the STL CAD model.
For more information regarding "stlread" function, kindly refer to the following documentation:
I hope this provides you with the required information regarding your query.
Regards,
Nithin Kumar.
  1 Commento
DGM
DGM il 15 Lug 2025
Modificato: DGM il 17 Lug 2025
Any reader that tries to use this example will get an error, then they'll look at the docs and be confused as to why it doesn't match the usage in the example.
The example is written for FEX #29906 or FEX #36771. These are all old, incomplete third-party decoders that nobody should be recommending for use in modern versions of MATLAB.
The docs link is for MATLAB's built-in stlread(). The built-in stlread is complete and robust, but it does not support the syntax of all the various old decoders with the same name. It returns a triangulation object and other file/face attributes -- not an FV struct, and not F,V lists.
Does that mean that the reader should go download some 15-year old incomplete decoder with problems they won't anticipate? No. Use the built-in decoder that you already have. The problem with that is that the entire example is written around using the behavior of the old function. Just use what you have.
unzip stepholecube.stl.zip % for the forum
% the inputs
T = stlread('stepholecube.stl');
point = [0.6 0.6 0.6];
% get the index of the nearest vertex
nv = nearestNeighbor(T,point); % that's it.
% plot everything
trisurf(T,'facecolor','w','edgecolor','k'); hold on
plot3(point(1),point(2),point(3),'*','linewidth',2)
plot3(T.Points(nv,1),T.Points(nv,2),T.Points(nv,3),'*','linewidth',2)
view(3); view(-30,47); camlight;
axis equal; grid on

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by