# Getting xyz coordinates for a specific point on stl cad model

17 次查看（过去 30 天）
Ahmed Tawfik 2022-12-14

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 个评论显示 无隐藏 无
Rik 2022-12-14
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?
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.

### 回答（1 个）

Nithin Kumar 2023-9-4
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.
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.
I hope this provides you with the required information regarding your query.
Regards,
Nithin Kumar.

### 类别

Help CenterFile Exchange 中查找有关 STL (STereoLithography) 的更多信息

### Community Treasure Hunt

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

Start Hunting!

Translated by