pol2cart — Transform polar or cylindrical coordinates to Cartesian coordinates.
Convert real polar or cylindrical coordinate arrays with implicit expansion and requested-output handling.
Syntax
[x, y] = pol2cart(theta, rho)
[x, y, z] = pol2cart(theta, rho, z)Inputs
theta- Type
Any- Required
- Yes
- Description
- Polar or cylindrical angular coordinate in radians.
rho- Type
Any- Required
- Yes
- Description
- Polar or cylindrical radial coordinate.
z- Type
Any- Required
- Yes
- Description
- Cylindrical elevation coordinate.
Returns
x- Type
NumericArray- Description
- Cartesian x coordinate.
y- Type
NumericArray- Description
- Cartesian y coordinate.
z- Type
NumericArray- Description
- Cartesian z coordinate.
Returned values from pol2cart depend on how many outputs the caller requests.
Errors
RunMat:pol2cart:InvalidInput- When
- An input is not a supported real floating-point scalar or array.
- Message
pol2cart: invalid input
RunMat:pol2cart:ComplexUnsupported- When
- At least one input is complex.
- Message
pol2cart: complex inputs are not supported
RunMat:pol2cart:SizeMismatch- When
- Input arrays do not have compatible sizes for implicit expansion.
- Message
pol2cart: size mismatch
Coordinate conventions and outputs
[x,y] = pol2cart(theta,rho) converts polar coordinates to Cartesian coordinates. [x,y,z] = pol2cart(theta,rho,z) converts cylindrical coordinates. Angles are radians measured counterclockwise from the positive x-axis; rho is radial distance and z is elevation.
The formulas are x = rho .* cos(theta) and y = rho .* sin(theta). All inputs participate in MATLAB-style implicit expansion, including z when only x and y are requested. The returned elevation is expanded without a trigonometric conversion. Empty and N-D arrays are supported.
The two-input form supports zero, one, or two requested outputs; the three-input form supports up to three. A single assignment or implicit output returns x. A discarded-output call still validates and evaluates the transform.
Numeric classes
Inputs must be real dense single or double scalars or arrays. The trigonometric step retains theta's floating precision; the x/y multiplication returns single when theta or rho is single, otherwise double. The z output retains the elevation's floating class independently.
RunMat mode independently permits all eight fixed-width integer classes for theta, rho, and z, provided every value is exactly representable as double. Integer values are validated before conversion and cross into floating computation once. MATLAB compatibility mode rejects these extensions. Logical, character, string, sparse, cell, struct, object, and complex inputs are not accepted.
Provider execution
Homogeneous floating inputs can be placed automatically after the complete two- or three-input form is validated. All data operands, the expanded output shape, and the requested output count participate in placement. Mixed floating classes retain the host formula so that coordinate and elevation precision are not silently changed.
Compatible real resident inputs can use their exact owning provider's sine, cosine, and broadcasted multiply operations. Borrowed input handles are preserved. Newly allocated intermediates and unrequested outputs are released on completion, failure, or cancellation.
Only an unsupported provider operation selects host fallback. Other provider failures and invalid output metadata remain errors. Mixed physical floating classes or providers use the host formula. Unsupported paths can return host values, so residency is not guaranteed for every input form.
This multiple-output transform terminates elementwise fusion rather than presenting a scalar fusion template. Distributed inputs use the shared materialization route.
Examples
Convert polar coordinates
theta = [0 pi/4 pi/2 pi];
rho = [5 5 10 10];
[x,y] = pol2cart(theta,rho)Expected output:
x = [5 3.5355 0 -10], y = [0 3.5355 10 0]Convert cylindrical coordinates
theta = [0 pi/2]';
rho = [1 2 3];
z = 7;
[x,y,z] = pol2cart(theta,rho,z)Expected output:
x = [1 2 3; 0 0 0], y = [0 0 0; 1 2 3], z = 7*ones(2,3)Expand single elevation into an N-D grid
elevation = reshape(single([7 8]), [1 1 2]);
[x,y,z] = pol2cart(single(0), [2 3], elevation);Expand resident coordinates using elevation
theta = gpuArray([0; pi/2]);
rho = gpuArray(2);
z = gpuArray([7 8 9]);
[x,y,z] = pol2cart(theta,rho,z);Using pol2cart with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how pol2cart changes the result.
Run a small pol2cart example, explain the result, then change one input and compare the output.
FAQ
What angle units does pol2cart use?⌄
Theta is in radians, measured counterclockwise from the positive x-axis.
Can I request only two outputs with three inputs?⌄
Yes. [x,y] = pol2cart(theta,rho,z) includes z in expansion but returns only x and y.
Does pol2cart accept complex inputs?⌄
No. Inputs must be real.
Does RunMat keep pol2cart on the GPU?⌄
Compatible real inputs remain resident when their owning provider supports the required sine, cosine, and broadcasted multiply operations. Unsupported forms fall back to host evaluation.
Related Math functions
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · atanh · cos · cosd · cosh · cospi · deg2rad · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh
Elementwise
abs · angle · besselj · bsxfun · complex · conj · double · eps · erf · erfcinv · exp · expm1 · flintmax · gamma · gammaln · heaviside · hypot · imag · int16 · int32 · int64 · int8 · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · times · typecast · uint16 · uint32 · uint64 · uint8
Optim
acceptancesa · annealingboltz · annealingfast · coneprog · crossoverarithmetic · crossoverheuristic · crossoverintermediate · crossoverlaplace · crossoverscattered · crossoversinglepoint · crossovertwopoint · eqnproblem · EquationProblem.solve · EquationProblem.subsasgn · EquationProblem.subsref · evaluate · fgoalattain · fitscalingprop · fitscalingrank · fitscalingshiftlinear · fitscalingtop · fminbnd · fmincon · fminimax · fminsearch · fminunc · fseminf · fsolve · fzero · ga · gacreationlinearfeasible · gacreationnonlinearfeasible · gacreationsobol · gacreationuniform · gacreationuniformint · gaplotbestf · gaplotbestindiv · gaplotdistance · gaplotexpectation · gaplotgenealogy · gaplotmaxconstr · gaplotrange · gaplotscorediversity · gaplotscores · gaplotselection · gaplotstopping · integerConstraint · integral · intlinprog · linprog · lsqcurvefit · lsqlin · LsqlinWarmStart.subsasgn · LsqlinWarmStart.subsref · lsqnonlin · lsqnonneg · mutationadaptfeasible · mutationgaussian · mutationpositivebasis · mutationpower · mutationuniform · optimexpr · optimget · OptimizationConstraint.evaluate · OptimizationConstraint.subsasgn · OptimizationConstraint.subsref · OptimizationExitflag.double · OptimizationExitflag.eq · OptimizationExitflag.ne · OptimizationExitflag.string · OptimizationExpression.acos · OptimizationExpression.acosh · OptimizationExpression.acot · OptimizationExpression.acoth · OptimizationExpression.acsc · OptimizationExpression.acsch · OptimizationExpression.asec · OptimizationExpression.asech · OptimizationExpression.asin · OptimizationExpression.asinh · OptimizationExpression.atan · OptimizationExpression.atanh · OptimizationExpression.cat · OptimizationExpression.cos · OptimizationExpression.cosh · OptimizationExpression.cot · OptimizationExpression.coth · OptimizationExpression.csc · OptimizationExpression.csch · OptimizationExpression.ctranspose · OptimizationExpression.cumprod · OptimizationExpression.cumsum · OptimizationExpression.diag · OptimizationExpression.diff · OptimizationExpression.dot · OptimizationExpression.eq · OptimizationExpression.evaluate · OptimizationExpression.exp · OptimizationExpression.ge · OptimizationExpression.horzcat · OptimizationExpression.ldivide · OptimizationExpression.le · OptimizationExpression.log · OptimizationExpression.mean · OptimizationExpression.minus · OptimizationExpression.mldivide · OptimizationExpression.mpower · OptimizationExpression.mrdivide · OptimizationExpression.mtimes · OptimizationExpression.norm · OptimizationExpression.plus · OptimizationExpression.power · OptimizationExpression.prod · OptimizationExpression.rdivide · OptimizationExpression.reshape · OptimizationExpression.sec · OptimizationExpression.sech · OptimizationExpression.sin · OptimizationExpression.sinh · OptimizationExpression.sqrt · OptimizationExpression.subsasgn · OptimizationExpression.subsref · OptimizationExpression.sum · OptimizationExpression.tan · OptimizationExpression.tanh · OptimizationExpression.times · OptimizationExpression.trace · OptimizationExpression.transpose · OptimizationExpression.uminus · OptimizationExpression.uplus · OptimizationExpression.vertcat · OptimizationExpression.zeros · OptimizationExpression.zerosLike · OptimizationProblem.solve · OptimizationProblem.subsasgn · OptimizationProblem.subsref · OptimizationVariable.subsasgn · OptimizationVariable.subsref · optimoptions · optimplotconstrviolation · optimplotfirstorderopt · optimplotfunccount · optimplotfval · optimplotfvalconstr · optimplotmilp · optimplotstepsize · optimplotx · optimproblem · optimset · optimvar · optimwarmstart · particleswarm · patternsearch · psplotbestf · psplotbestx · psplotfuncount · psplotmaxconstr · psplotmeshsize · pswcreationuniform · pswplotbestf · quad · quadprog · QuadprogWarmStart.subsasgn · QuadprogWarmStart.subsref · saplotbestf · saplotbestx · saplotf · saplotstopping · saplottemperature · saplotx · savemilpsolutions · secondordercone · selectionremainder · selectionroulette · selectionstochunif · selectiontournament · selectionuniform · simulannealbnd · solve · surrogateopt · surrogateoptplot · temperatureboltz · temperatureexp · temperaturefast
Reduction
all · any · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Signal
blackman · butter · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Interpolation
griddedInterpolant · griddedInterpolant.subsref · interp1 · interp1q · interp2 · pchip · ppval · spline
Integer Division
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.