Plot 2D Spring

Easily generate coordinates of 2D springs for plotting and animation.
226 Downloads
Updated 21 Nov 2018

--------------------------------- Tutorial ---------------------------------

'Spring.m' is a class file which generates coordinates of a 2D spring for plotting. A new spring instance can be created by passing 'spring radius' and 'number of coils'. For example:
```
spr = Spring(5, 10);
```
creates a spring instance `spr` with radius of 5 and coils number of 10. This instance gives coordinates of a spring connecting two arbitrary points by passing the coordinates of the two points into 'spr.getSpr(point1, point2)'. For example:
```
[x, y] = spr.getSpr([-1, 5], [4, 2]);
```
returns the coordinates of the spring connecting point (-1, 5) and point (4, 2), and then you could simply visualize the spring by using:
```
plot(x, y);
```
More details can be found in the demo files.

--------------------------------- Demo Files ---------------------------------

--- demo_StaticSpring.m ---

This demo file plots a simple static spring connecting two arbitrary points.

--- demo_MovingSpring.m ---

This demo file makes an animation of three moving points connectted by two different springs.

Cite As

Xue-She Wang (2025). Plot 2D Spring (https://github.com/wangxueshe/Plot-2D-Spring-in-Matlab), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2017a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Animation in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes
1.0.1

Picture updated.

1.0.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.