フィルターのクリア

Writing a function that returns the 5 coordinates to draw a square?

3 ビュー (過去 30 日間)
Jason
Jason 2013 年 3 月 26 日
I have this so far... [x,y] = square_points(center_x , center_y, length)
And it is supposed to return the 5 coordinates needed to draw a square of side length (length) with its position at (center_x,center_y)
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 26 日
What is square_points?
Cedric
Cedric 2013 年 3 月 27 日
編集済み: Cedric 2013 年 3 月 27 日
How would you compute these coordinates by hand? Don't start "thinking in MATLAB code"; solve your problem on paper first, and only once it is completely clear to you what it is that has to be computed and how, can you start thinking about the implementation.
Also, base your reasoning on some simple example, e.g. take (6,5) as coordinates of the center and 4 for the length of the edges.

サインインしてコメントする。

回答 (1 件)

Matt Kindig
Matt Kindig 2013 年 3 月 26 日
編集済み: Matt Kindig 2013 年 3 月 26 日
The nice thing about Matlab is that, for simple equations, the correct syntax looks almost identical to how you would write the formula out by hand. So I would start with this. Write down (on paper), the equations of the coordinates of the square corners, in terms of variables Cx (center-X), Cy (center-Y) and L (length). Once you do this, converting them to Matlab is trivial.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by