用java计算三角形的邻边?
我正在开发一个应用程序,可以计算梯子距离墙壁的距离,在这种情况下,梯子是斜边,其值将根据用户输入而变化,因此将以英尺为单位计算,X = 73 度, A = cos 73 相邻/斜边。检查下面的图像以更好地理解:
我做了一些研究,发现了梯级之间的距离梯子大约 1 英尺,用户必须计算梯级数量并将该数字输入到 EditText
中,然后按下按钮计算结果,同时使用 Toast 显示结果。 那么我如何能够使用java中的三角函数来计算A以及我如何能够将字符串从EditText
转换为双精度请帮我弄清楚我正在这里从事一个学校项目是到目前为止,我的代码,请告诉我必须添加或删除哪些内容,谢谢您的宝贵时间!
另外,我已手动将 A 转换为弧度,因为我也不知道如何将度数转换为弧度!
package com.ladder;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.lang.Math;
public class LadderActivity extends Activity { double x;
double r = Math.cos(1.274090354);
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText edt1 = (EditText) findViewById(R.id.et1);
String k = edt1.toString();
Button btn = (Button) findViewById(R.id.bt1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), " FT", Toast.LENGTH_SHORT).show();
// TODO Auto-generated method stub
} });
} }
I am working on an application that can calculate how far a ladder has to be from the wall in this case the ladder is the hypotenuse and the value of that will vary on the users input so it will be calculated in feet , X = 73 degrees, A = cos 73 Adjacent/Hypotenuse. Check the bellow image to understand better:
I did some research and I found out the distance between the rungs on a ladder are about 1 feet, the user would have to count the number of rungs and input that number to the EditText
and press the button to calculate the results while displaying it using Toast.
SO how would I be able to calculate A using trigonometric functions in java and how would I be able to convert the strings from EditText
to a double please help me figure this out am working on a school project here is my code so far, please tell me what I have to add or remove thank you for your time kind of new to this!
Also I have manually converted A to radians since I do not know how to convert degrees to radians also!
package com.ladder;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.lang.Math;
public class LadderActivity extends Activity { double x;
double r = Math.cos(1.274090354);
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText edt1 = (EditText) findViewById(R.id.et1);
String k = edt1.toString();
Button btn = (Button) findViewById(R.id.bt1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), " FT", Toast.LENGTH_SHORT).show();
// TODO Auto-generated method stub
} });
} }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用java的Math类,下面是您问题的详细答案
将字符串从 Edittext 转换为双精度
如何将度数转换为弧度
这些是三角形的边
计算“相邻”值。
计算相反值
计算斜边值
You can use Math class of java and below is detailed answer of your question
Convert string from Edittext to double
How to convert Degree into radian
These are sides of triangle
Calculate 'Adjacent' Value.
Calculate Opposite Value
Calculate Hypotenuse Value