在MATLAB中的两个笛卡尔点之间创建螺旋 [英] Create a spiral between two cartesian points in MATLAB

查看:197
本文介绍了在MATLAB中的两个笛卡尔点之间创建螺旋的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这是一个基本的问题,但是我一直找不到这样的东西,我想知道如何以最佳方式做到这一点.

Perhaps this is a basic question but I haven't been able to find anything specifically like this and I'm wondering how to do it in the best way.

我有两组点(x1,y1,z1)和(x2,y2,z2),我已将它们转换为极坐标.我想创建一个半径逐渐减小的逆时针螺旋线以到达第二个点.

I have two sets of points (x1,y1,z1) and (x2,y2,z2) and I have converted them into polar coordinates. I would like to create a counter-clockwise helix of decreasing radius to reach the second point.

我还要指定需要转多少圈.

I would also like to specify how many revolutions it takes.

我所看到的所有示例都是x轴上的两个点,并且都是顺时针旋转的.

All of the examples I have seen are two points on the x axis and going clockwise.

任何建议将不胜感激!

谢谢.

推荐答案

此示例代码生成从p1到p2的逆时针螺旋,该螺旋不在x轴上,您可以指定转数.但是,它是二维的,起始点是笛卡尔坐标.我不确定如何在3D模式下执行此操作,但我希望这可以帮助您实现偏移和逆时针旋转.

This example code generates a counter clockwise spiral from p1 to p2 that isn't on x-axis and you can specify the number of revolutions. However it is in 2D and initial points are in cartesian coordinates. I'm not sure how to do it in 3D but I hope this can help you with the offsetting and the counter-clockwising.

%random 2d points
p1 = [3,5];
p2 = [1,4];

%radius of first point to second
r = norm(p1-p2);
%angle between two point wrt the y-axis
theta_offset = tan((p1(2)- p2(2))/(p1(1)-p2(1)));

rez = 150; % number of points 
rev = 5; % number of revolutions

t = linspace(0,r,rez); %radius as spiral decreases
theta = linspace(0,2*pi*rev,rez) + theta_offset; %angle as spiral decreases
x = cos(theta).*t+p2(1); 
y = sin(theta).*t+p2(2);
plot(x,y)

这篇关于在MATLAB中的两个笛卡尔点之间创建螺旋的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆