MATLAB uses polar coordinates to transform the relative length of a segment

Source: Internet
Author: User

Today in the MATLAB forum, there is a friend of the altar to draw a known relative angle relative length of continuous segments.

Looked up some information and thought about some ways. It is found that it can be solved by using polar coordinates to draw vectors and then by the way of vector superposition. Write a Trans_cood function:

1function [lx,ly] =Trans_cood (x,y,rho,r)2th = [0; rho*pi/ the]; 3Rho = [0;  R]; 4[Xvec,yvec] =Pol2cart (Th,rho); 5Lx (1) =x; 6Ly (1) =y; 7Lx (2) = x + Xvec (2); 8Ly (2) = y + Yvec (2);

In this function Pol2cart generates a starting point for (0,0), the angle is determined by rho, and the relative length is determined by the vector of R. Adding this vector to the origin, we get the required continuous segment coordinates LX (2), Ly (2).

Example: Follow this example to draw a path map:?

1p_x =0; P_y =0; 2Rectangle'Position', [0 0 4 4.598]); 3x =0; y =0; 4RHO = [ -,0, -, -, -, -, -, -, -, -, -, -, the, -, -, -, -, -, -, -, -, -, -,0, -, -, -, -, -, -,0, the]; 5   6R = [0.866025403784439,0.500000000000000,1,1,1,1,1,1,1,0.866025403784439,1,0.866025403784439,0.500000000000000,1,1,1,1,1,1,1,0.866025403784439,1,0.866025403784439,0.500000000000000,1,1,1,1,1,1,0.500000000000000,0.866025403784439]; 7  fori =1: +  8[Lx,ly] =Trans_cood (X,y,rho (i), R (i)); 9x = Lx (2); y = Ly (2); P_x =[p_x Lx (2)]; p_y = [P_y Ly (2)]; Ten End One axis Equal APlot (p_x,p_y,'o','Markerfacecolor','R','Markeredgecolor','k','markersize',Ten);  -H = Quiver (p_x (1: end-1), P_y (1: end-1), P_x (2: End)-P_x (1: end-1), P_y (2: End)-P_y (1: end-1));  -Axis ([-0.5 4.5-0.5 5]);  the SetH'Color','b','maxheadsize',0.1);  -box on;?

MATLAB uses polar coordinates to transform the relative length of a segment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.