How to convert X, Y, Z cartesian coordinates into a surface. (2024)

60 ビュー (過去 30 日間)

古いコメントを表示

Kylen 2024 年 4 月 11 日 18:48

  • リンク

    この質問への直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface

  • リンク

    この質問への直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface

コメント済み: Voss 2024 年 4 月 12 日 17:09

採用された回答: Voss

  • nosecone.mat

Hello,

I have three vectors representing x, y, and z cartesian coordinates of half of a nosecone shape. I need to convert the z data into a "matrix of z heights", as as described in the documentation for Grid Surfaces used in Simscape Multibody (https://www.mathworks.com/help/sm/ref/gridsurface.html#mw_e7b9ffe5-592d-4971-9715-092dba7fd93a).

I tried to use the diag() command and surf() to check things, but it isn't quite right; there are valleys between rows of points and some of the negative space outside the nosecone is also included. Additionally, Simscape grid surfaces need x and y vectors that are monotonic and increasing. I can sort these vectors in Matlab easily enough, I can't seem to get my z matrix quite right when I sort x and y.

Sample code below. The x_coords, y_coords, and z_coords are pulled in from a .mat file.

Thank you!

load('cone_data - Copy.mat');

x = x_coords(:);

y = y_coords(:);

z = z_coords(:);

z = diag(z);

fullset = [x y z];

surf(x, y, z);

4 件のコメント

2 件の古いコメントを表示2 件の古いコメントを非表示

Voss 2024 年 4 月 11 日 19:21

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3128901

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3128901

Can you upload the mat file, using the paperclip button?

Kylen 2024 年 4 月 11 日 20:22

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3128951

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3128951

Hi, thanks for asking. I added a .mat file. It's the x, y, z data in three columns. My original .mat was given to me unsorted (many columns for each x, y, z), so I uploaded the version that's a bit less cumbersome.

Anyway, my attachment is x, y, z. The z column is giving me trouble. I think I might need to interpolate between points to get a surface. I've tried using diag() to kind of fill in the "empty" spots with zeros. That was helpful, but not quite right.

If you hadn't guessed, this is a little outside of my wheelhouse, so I appreciate the help.

Cris LaPierre 2024 年 4 月 11 日 20:43

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3128981

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3128981

  • nosecone.mat

Please upload the same data you are working with.

The mat file you uploaded does not appear to have the same variables your code uses.

load nosecone.mat

whos

Name Size Bytes Class Attributes ans 1x36 72 char cmdout 1x33 66 char full 675x3 16200 double gdsCacheDir 1x14 28 char gdsCacheFlag 1x1 8 double i 0x0 0 double managers 1x0 0 cell managersMap 0x1 8 containers.Map

Kylen 2024 年 4 月 11 日 20:47

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3128991

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3128991

  • cone_data - Copy.mat

Attached. Thanks.

サインインしてコメントする。

サインインしてこの質問に回答する。

採用された回答

Voss 2024 年 4 月 12 日 15:30

  • リンク

    この回答への直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#answer_1440481

  • リンク

    この回答への直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#answer_1440481

  • cone_data - Copy.mat

load('cone_data - Copy.mat');

Here's how the surface looks. This is using the matrices x_coords, y_coords, and z_coords.

% a surface based on x, y, and z matrices

figure

surf(x_coords,y_coords,z_coords)

How to convert X, Y, Z cartesian coordinates into a surface. (7)

I understand that for Simscape Multibody you need to specify the surface as a matrix z based on x and y being monotonically increasing vectors, instead of matrices. That constraint is the same as requiring the surface to have a footprint (i.e., its projection on the x-y plane) that is a rectangle. Obviously the surface above does not have a rectangular footprint; it's more like a filled-in parabola kind of shape. In order to define your surface on a rectangular footprint, you'll need to fill in some z values outside the parabola. Using zeros is a natural choice for those values, which can be done something like this:

% need to interpolate x/y/z_coords over some rectangular

% grid, so use a scatteredInterpolant

SI = scatteredInterpolant(x_coords(:),y_coords(:),z_coords(:));

Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.

% define the grid with some equally-spaced x values

x = linspace(min(x_coords(:)),max(x_coords(:)),25);

% and non-equally-spaced y values (because y_coords is already grid-like)

y = y_coords(:,1);

% interpolate to get z on that grid

[X,Y] = meshgrid(x,y);

Z = max(0,SI(X,Y));

% surface based on x, y vectors, and matrix z

figure

surf(x,y,Z);

How to convert X, Y, Z cartesian coordinates into a surface. (8)

Another choice might be NaNs (I have no idea what Simscape Multibody will do with NaN z values, but it's worth a shot, I guess), which can be done like this:

% using the same x-y grid as before, but

Z = SI(X,Y);

Z(Z < 0) = NaN;

% surface based on x, y vectors, and matrix z

figure

surf(x,y,Z);

How to convert X, Y, Z cartesian coordinates into a surface. (9)

I guess I would try the one with the zeros first.

4 件のコメント

2 件の古いコメントを表示2 件の古いコメントを非表示

Kylen 2024 年 4 月 12 日 16:11

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3129906

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3129906

Hello, and thank you so much! This is the closest I've gotten so far. I think your first version with the zeros will work for my purposes. I'll be contact modeling on the top contours of the curve, so the "flat" underside shouldn't really come into play.

Do you happen to have a suggestion for the following Simscape error?

  • ['untitled/Grid Surface']: The number of elements in the X Grid Vector parameter must equal the number of rows in the Z Heights matrix parameter. Resolve this issue in order to simulate the model.
  • ['untitled/Grid Surface']: The number of elements in the Y Grid Vector parameter must equal the number of columns in the Z Heights matrix parameter. Resolve this issue in order to simulate the model.

I tried to take transpose x and y such that the dimensions match that of the Z matrix, but that didn't seem to work either.

Again, thanks for helping!

Voss 2024 年 4 月 12 日 16:22

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3129916

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3129916

  • cone_data - Copy.mat

You're welcome!

Transpose Z or use ndgrid rather than meshgrid to get rid of those errors.

Double-checking:

load('cone_data - Copy.mat');

% need to interpolate x/y/z_coords over some rectangular

% grid, so use a scatteredInterpolant

SI = scatteredInterpolant(x_coords(:),y_coords(:),z_coords(:));

Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.

% define the grid with some equally-spaced x values

x = linspace(min(x_coords(:)),max(x_coords(:)),25);

% and non-equally-spaced y values (because y_coords is already grid-like)

y = y_coords(:,1);

Z is numel(y)-by-numel(x) because that's convenient for plotting a surface

% interpolate to get z on that grid

[X,Y] = meshgrid(x,y);

Z = max(0,SI(X,Y));

whos x y Z

Name Size Bytes Class Attributes Z 27x25 5400 double x 1x25 200 double y 27x1 216 double

But Simscape Multibody expects Z to be numel(x)-by-numel(y)

% interpolate to get z on that grid

[X,Y] = ndgrid(x,y);

Z = max(0,SI(X,Y));

whos x y Z

Name Size Bytes Class Attributes Z 25x27 5400 double x 1x25 200 double y 27x1 216 double

Kylen 2024 年 4 月 12 日 16:43

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3129941

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3129941

  • Surf.PNG

Thank you! This should be more than adequate for my purposes.

My teammate and I are eternally grateful!

Voss 2024 年 4 月 12 日 17:09

このコメントへの直接リンク

https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3129971

  • リンク

    このコメントへの直接リンク

    https://jp.mathworks.com/matlabcentral/answers/2105821-how-to-convert-x-y-z-cartesian-coordinates-into-a-surface#comment_3129971

You're welcome! Please "Accept" this answer if it ends up working.

サインインしてコメントする。

その他の回答 (0 件)

サインインしてこの質問に回答する。

参考

カテゴリ

Physical ModelingSimscape MultibodyMultibody ModelingBodies

Help Center および File ExchangeBodies についてさらに検索

タグ

  • grid surface
  • simscape multibody
  • diagonal
  • cartesian coordinates

製品

  • MATLAB
  • Simscape Multibody

Community Treasure Hunt

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

Start Hunting!

エラーが発生しました

ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。


Translated by How to convert X, Y, Z cartesian coordinates into a surface. (14)

How to convert X, Y, Z cartesian coordinates into a surface. (15)

Web サイトの選択

Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:

また、以下のリストから Web サイトを選択することもできます。

南北アメリカ

  • América Latina (Español)
  • Canada (English)
  • United States (English)

ヨーロッパ

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

アジア太平洋地域

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

最寄りの営業オフィスへのお問い合わせ

How to convert X, Y, Z cartesian coordinates into a surface. (2024)
Top Articles
Latest Posts
Article information

Author: Stevie Stamm

Last Updated:

Views: 5418

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Stevie Stamm

Birthday: 1996-06-22

Address: Apt. 419 4200 Sipes Estate, East Delmerview, WY 05617

Phone: +342332224300

Job: Future Advertising Analyst

Hobby: Leather crafting, Puzzles, Leather crafting, scrapbook, Urban exploration, Cabaret, Skateboarding

Introduction: My name is Stevie Stamm, I am a colorful, sparkling, splendid, vast, open, hilarious, tender person who loves writing and wants to share my knowledge and understanding with you.