このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。

翻訳前ページへ


Angle calculator- Lazarus HOME - - - - - Lazarus Tutorials TOC - - - - - - Other 構成要素 for programmers

A Lazarus programming challenge!

     (とじ込み/提出する: ltn8chall-angles.htm)

This page throws 負かす/撃墜する a challenge: Can you 令状 the program I need?.. in Lazarus, for my wants... but you could have fun with the challenge for your own 目的s in most languages. It all arises out of my 地図/計画する Making challenges for schools, 青年 groups, "team building" 演習 組織者s.

There's not a lot of programming to 達成する the first 行う/開催する/段階 of 完全にするing the challenge... but there's some tedious mathematics to しっかり掴む. I will help you with the mathematics.

You can download the sourcecode of the 爆撃する of the program. (公式文書,認める that there's also a link to a "finished" 見解/翻訳/版, 近づく the 底(に届く) of the page.)


Get the first challenge 達成するd, and then the "real fun" begins! More on that later.

Here's the first challenge...

Suppose I give you the 調整するs of three points on a surface....

-

If you draw lines, as above, three points define an angle.

The challenge? 令状 a subroutine to calculate the angle from the 調整するs of the points.

It isn't as hard as it seems. 特に if I 約束 several things. (I know the に引き続いて will look "hard", but just take it slowly with an "I CAN do this" 態度! It ISN'T 現実に hard....)

Why do those things 事柄? For now, just 信用 me? (We'll talk about it again, much later, when I change the 支配するs for the second part of the challenge... when things become much harder!)

The first part of the challenge is just to create a little 使用/適用 which will look like this when you run it...

-

The six numbers (70, 30, 10, 20, 40 and 30) are the 調整するs of the three points. They go in edit boxes. (Or, if you would rather, a small text とじ込み/提出する.. but if you use that method, and read the text とじ込み/提出する as part of the DoIt handler, copy the 6 values to the 審査する, so it looks like the screenshot anyway.)

The screenshot (from a mock up of the 使用/適用 that you are challenged to create) shows what the window should look like AFTER the "Do It" button has been clicked.

(The answer, by the way is almost certainly NOT 20.7 !! That is only だいたい 権利! (It was put into the image with a kludge before I knew the exact answer.))

So! You know what the 審査する should look like.

A bit about the structure of the code that I 要求する of you... "getting the 権利 answer" is NOT enough... it also needs to be done the 権利 way!

Here's a sketch of the OnClick handler for the button captioned "Do It"....

手続き TLDN185f1.buDoItClick(Sender: TObject);
  var rAns:real;
    x0,y0,x1,y1,x2,y2:integer;
begin
  //(fill x0, y0, x1, etc with the values you
  //   want to do the 計算/見積り for)
  rAns:=rAngleFromCoords(x0,y0,x1,y1,x2,y2);
  laAns.caption:=floattostr(rAns);
end;

If, as would make sense, you use edit boxes as the way the 使用者 will tell the 使用/適用 the values of the 調整するs, you run the 危険 that a 使用者 will enter something other than text. It is not necessary to を取り引きする that in any depth in 試みる/企てるing the challenge. Maybe just 始める,決める a 旗, and have laAns.caption show "無効の input" unless the 旗 is (疑いを)晴らす.

Here's what the subroutine looks like at the moment...

機能(する)/行事 TLDN185f1.rAngleFromCoords(x0,y0,x1,y1,x2,y2:integer):real;
begin
  result:=20.7;
end;

Yes! The program has two x0's, two y0's, etc.

I don't see this as 存在 a problem. The 準備/条項s for 範囲 in the language take care of the "problem". In the program this is needed for, when you are working at a "high" level, you won't know what variable 指名するs are used inside the sub-決まりきった仕事 you will be using. And when you are working on the sub-決まりきった仕事's code, you won't be thinking about what variable 持つ/拘留する those values in the "outside" program. Ah, the joys of 封鎖する oriented programming!

See if you can 令状 the code for the subroutine!

KEEP the elements 現在の in the "sketch" above, e.g. the variable 指名するs and what part of the 使用/適用 was broken out into the subroutine.

Use the same variables, and variable types, in the 鮮明度/定義 of the subroutine.

Please!


How To Do It

I hope the に引き続いて hints will be enough that you can see what has to be done? By all means 令状, ask, if bits are 不明瞭な.

-

Here, to save you scrolling, is "the problem" again. And, just to remind you: You have to work out how big the angle ("A") is. In degrees, please. (Not radians... if you've heard of them?)

The first part of working out the size of the angle is to "slide" the angle 負かす/撃墜する and left, until the apex is on the 0,0 point of the Cartesian 計画(する). (For those who know: The "proper" 指名する for what I am speaking about is "translate", not "slide". For those who aren't sure what I mean, look at the diagram. The red angle is the result of 事情に応じて変わる/ translating the one we started with to where it needs to be... with the apex at 0,0)

You don't have to 供給する any graphics for the 使用/適用. This "事情に応じて変わる 負かす/撃墜する" happens only "inside" the 使用/適用.

-

We translate the angle by subtracting one constant number from all three of the x 調整するs, and a かもしれない (but not always) different second constant number from all of the y 調整するs. Check the numbers in the diagram. Be sure you are "on the same page" as I'm on.) (Don't worry about angle B yet.)


If we "clean that up" a bit, it is 平易な to see the angle we 手配中の,お尋ね者 to know about. And there's another angle, "B".

-

We can 人物/姿/数字 out what angle A and B make together... let's say it is 35 degrees. And we can 人物/姿/数字 out how big angle B is. Let's say it is 15 degrees. If we knew those things, we'd know that angle A is 20 degrees!

But how do we know those things?

With trigonometry! Which you won't need to (fully) understand to 達成する the challenge. (I may need to 令状 the trig up more than this... but I'm hoping not! As a math teacher to help?)

A digression: I am, in a moment, going to speak of the "arctan" 機能(する)/行事. That's the 機能(する)/行事 that tells you the angle, if your tell it what the length of the opposite 味方する divided by the 隣接する 味方する comes to. E.g. If the opposite 味方する is 5 部隊s long, and the 隣接する 味方する is 5 部隊s long, then opposite divided by 隣接する comes to 1, and, after you 変える the answer from radian to 法令s, the arctan of 1 is 45 degrees. It is also called the inverse 機能(する)/行事 of tan, or "cotan". (Thank you, https://www.mathsisfun.com/algebra/trig-finding-angle-権利-triangle.html, for reminding me of the 詳細(に述べる)s!)

In trig 条件, from our diagram, we know the "opposite" and "隣接する" 味方するs of a 権利 triangle: 40,20 / 0,0 / 40,0. (That last point isn't 示すd on the diagram. You see where it goes, though, don't you? And you see the 権利 triangle? And you see that the 隣接する 味方する is 40 部隊s long, and the opposite 味方する is 20 部隊s long? Hurrah! cotan(Opposite/隣接する), i.e. arctan(20/40), arctan(0.5) will give us the size of the angle made up of "B" and "A" together... 26.56 degrees.

適用するing the same logic, arctan(10/60) gives us the size of "B"... 9.46 degrees.

So.. "B" alone is 17.10 degrees!



The 明確な/細部s of the challenges!...

First Challenge... "All" you have to do is...

"All" you have to do is to turn the 事情に応じて変わる, the 計算/見積り of the two angles (in degrees), and the subtraction of the two... and you'll be done... with the first part of the challenge!

Hint: RadToDeg and arctan are two Lazarus 機能(する)/行事s which will be useful in this 仕事...

RadToDeg(arctan(Opposite/隣接する));

("ArcTan()" returns the answer in radians. RadToDeg 変えるs them to degrees. To use RadToDeg, you have to 追加する "Math" to the 名簿(に載せる)/表(にあげる) of 部隊s the 使用/適用 uses.... just 追加する it to the "USES" 名簿(に載せる)/表(にあげる) at the 最高の,を越す of your code.)

Hurrah! A nice 解答!...

My fulsome thanks to the 肉親,親類d reader who submitted a very nice 解答.

Before you 急ぐ off, and look at the answer... are you sure you don't want to 試みる/企てる the challenge for your own amusement (and 利益) first? It should take about 20 minutes... and if it doesn't, Making It Work will 強化する your coding 技術s, so that the next one DOES take only 20 minutes. (Remember: There's a "爆撃する" already 用意が出来ている for you, downloadable from the link 近づく the 最高の,を越す of this page.)

I zipped up the sourcecode submitted, with a copy of the exe for you, and put it online, so you can download it. (The filename will be LTN8chall-angles19222.zip)

His 解答 is neat and clean. It takes only 受託するs integers for the 調整する specifications... which is 罰金. If his 解答 is 延長するd to solving the second challenge, 制限するing things to integers probably costs nothing in the use ーするつもりであるd for the result. (You can 手段 the points in the gym in ミリメートルs, if you think it 事柄s.) And it makes the code more efficient... always a worthy goal. Okay. With 200 data points and a modern computer, perhaps we get the result in 0.9 seconds instead of 2.7, but it still a worthy goal!

At the heart of his program....

  機能(する)/行事 rAngleFromCoords(x0,y0,x1,y1,x2,y2: integer): real;
  var A1, A2 : real;
  begin
    A1 := arctan((y2-y1)/(x2-x1));
    A2 := arctan((y0-y1)/(x0-x1));
    result := RadToDeg(A1-A2);
  end;

That's it. That gives you the angle from just the 調整するs of the apex, and a point on either 味方する.

Math(s) can be beautiful! If you have the soul to see it.

Second challenge....

There were things in what I 約束d for the three 調整するs which made part 1 of the challenge "平易な".

Part two of the challenge 身を引くs some of those 約束s. The basic technique will still be the same. The code will (mostly) be the same... in fact, changes should ONLY be made within the 機能(する)/行事 鮮明度/定義...

機能(する)/行事 TLDN185f1.rAngleFromCoords(x0,y0,x1,y1,x2,y2:integer):real;
begin
  result:=20.7;
end;

Please don't be "shy"... successes with "only" part 1 of the challenge would be of 利益/興味. If you help me with "camera ready" 構成要素, I would be glad to showcase what you have done, here.

Please understand: Part (only part) of the 推論する/理由 for creating this page was to get someone else to do the programming for me. (Just doing it myself would have been much いっそう少なく work than doing this page!)... I will assume that you are "giving away ALL your 権利s" to any code you 服従させる/提出する for 祝賀 here. I might 井戸/弁護士席 publish it. I, and others, may produce derivative 作品, and will point to this, if you ask for any 支払い(額). I will give you credit, on some level, if I use your stuff. I can't 約束 that others will.



   Search this 場所/位置 or the web        力/強力にするd by FreeFind
 
  場所/位置 search Web search
場所/位置 地図/計画する    What's New    Search   BEWARE: There is stuff at my other two 場所/位置s that the search above won't 明らかにする/漏らす. Go to either 場所/位置 (see links below) and use that 場所/位置's FreeFind search button.

BEWARE: The search above only visits a 選択 of my stuff. Go to either of my other 場所/位置s (see links below) and use that 場所/位置's FreeFind search button, if you 港/避難所't 設立する something you "know is there".


In 新規加入 to the tutorials for which this page serves as (米)棚上げする/(英)提議する of Contents, I have other 場所/位置s with 構成要素 you might find useful.....

My other 場所/位置s....
Sheepdog ソフトウェア homepage.
My Arunet homepage.

... and some links to 明確な/細部 pages within them you might want....
You can't "play" all day... learn to use the Libre Office/ Open Office database. 解放する/自由な. Multi-壇・綱領・公約.
The Arduino- LOTS of fun, for not much money. And beginner (intelligent beginner) friendly. And good 追跡 for kids. 連合させる programming and electronics!
Designing printed 回路・連盟 boards the KiCad way. 解放する/自由な. Multi-壇・綱領・公約. Long 設立するd. PCB-fab houses take native KiCad とじ込み/提出するs.
And lastly... Making 地図/計画するs... how we did it before GPS Indulge me? This discusses a worthwhile, fun (if 現在のd intelligently) activity for kids, which can be undertaken on many levels... a simple 20 minutes, or weeks of engaging activity. (Also known to コースを変える susceptible adults.)


広告 from page's editor: Yes.. I do enjoy 収集するing these things for you... hope they are helpful. However.. this doesn't 支払う/賃金 my 法案s!!! If you find this stuff useful, please at least help me with Facebook links, etc (buttons at 最高の,を越す of page). If you run an MS-DOS or Windows PC, please visit my freeware and shareware page, try something? Links on your page to this page would also be 高く評価する/(相場などが)上がるd, of course!
Click here to visit editor's freeware, shareware page.


   Here is the way to 接触する the author of these Lazarus/Delphi tutorials, Tom Boyd.





Valid HTML 4.01 Transitional Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.

AND passes... Valid CSS!

If this page 原因(となる)s a script to run, why? Because of things like Google パネル盤s, and the code for the search button. Why do I について言及する scripts? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....