Drawing a trapezium in matlab

Is there a quick way, apart from using vertices, to draw an isosceles trapezium given the height and the length of both parallel sides? Thank you.

 Accepted Answer

KSSV
KSSV on 23 Feb 2018
Edited: KSSV on 23 Feb 2018
h = 1 ; % height
a = 2 ; % top side
b = 4 ; % base
%%Frame vertices
A = [0 0] ;
B = [b 0] ;
C = [0.5*(b-a)+a h] ;
D = [0.5*(b-a) h] ;
coor = [A ; B; C; D] ;
patch(coor(:,1), coor(:,2),'r')
Refer here how the coordinates are formed: http://mathworld.wolfram.com/IsoscelesTrapezoid.html

4 Comments

Thank you that works!
Would you be able to elaborate on the patch function? I 'm not sure what is happening there
See patch().
The argument list are x-coordinates, y-coordinates, and the line color.
A,B,C,D are [x y] pairs. They're simply concatenated to form the 4x2 matrix coor, from which the x,y vectors are taken in the call to patch().
thank you , I see it now.

Sign in to comment.

More Answers (0)

Tags

Asked:

on 23 Feb 2018

Commented:

on 19 Aug 2023

Community Treasure Hunt

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

Start Hunting!