Getting xyz coordinates for a specific point on stl cad model
조회 수: 40 (최근 30일)
이전 댓글 표시
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?
Askic V
2023년 1월 18일
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.
[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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!