2018.09.14 15:33
bool lineIntersection(cv::Point2f &c1, cv::Point2f &c2, cv::Point2f &d1, cv::Point2f &d2, cv::Point2f &intersection) {
	/*

	두 점 A(x1, y1), B(x2, y2)을 잇는 직선의 방정식
	y = ax + b (a : 기울기 = y증가량/x증가량, b : 상수)
	a = (y2-y1)/(x2-x1)
	y = (y2-y1)/(x2-x1)x + b
	b = y - (y2-y1)/(x2-x1)x
	b = y1 - (y2-y1)/(x2-x1)x1

	!!!!! y = (y2-y1)/(x2-x1)x + (y1 - (y2-y1)/(x2-x1)x1) !!!!!

	방정식 1 : y = a1x + b1
	방정식 2 : y = a2x + b2
	(a1-a2)x = (b2-b1)
	x = (b2-b1)/(a1-a2)
	방정식 1에 대입하면
	y = a1((b2-b1)/(a1-a2)) + b1
	 
	교점의 좌표 (x,y) = ( (b2-b1)/(a1-a2), a1((b2-b1)/(a1-a2)) + b1)

	 */

	float a1, b1, a2, b2;
	a1 = (c2.y - c1.y) / (c2.x - c1.x);
	//b1 = c1.y - (((c2.y - c1.y) / (c2.x - c1.x))*c1.x);
	b1 = c1.y - (a1*c1.x);
	//cout << "test:x:" << intersection.x << endl;

	a2 = (d2.y - d1.y) / (d2.x - d1.x);
	//b2 = d1.y - (((d2.y - d1.y) / (d2.x - d1.x))*d1.x);
	b2 = d1.y - (a2*d1.x);

	if (a1 == a2) return false;//평행이나 일치인 경우

	intersection.x = (b2- b1) / (a1 - a2);
	intersection.y = a1*(intersection.x) + b1;
	cout << "test:x:" << intersection.x << endl;
	cout << "test:y:" << intersection.y << endl;
	return true;

};
Posted by 너부리이놈
2018.09.10 14:04


AlertDialog.Builder builder;
final AlertDialog dialog;

final Context mContext = MainActivity.this;

LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
//View layout = inflater.inflate(R.layout.enroll_dialog, (ViewGroup)findViewById(R.id.enroll_layout_root));
View layout = inflater.inflate(R.layout.test_dialog, null);

final EditText enrolleditText = (EditText)layout.findViewById(R.id.test_editText);


builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
builder.setPositiveButton(android.R.string.ok, null); //Set to null. We override the onclick
builder.setNegativeButton(android.R.string.cancel, null);
dialog = builder.create();
dialog.show();

//Overriding the handler immediately after show is probably a better approach than OnShowListener as described below
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String getId = enrolleditText.getText().toString();
if (!(getId.isEmpty()))
{
Toast.makeText(mContext,"success",Toast.LENGTH_SHORT).show();
dialog.dismiss();
} else {
//return;
Toast.makeText(mContext,"insert name",Toast.LENGTH_SHORT).show();
}
}
});

dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});


Posted by 너부리이놈
2018.09.04 11:06

안드로이드 첫 액티비티(Launcher)에서 인텐트 수신


그냥 이런식으로 받게되면

String phase = getIntent().getStringExtra("phase");


null 값 오류가 발생


번들을 먼저 받고 getString("key값","기본값")를 하면 기본값 세팅이 가능해 짐

Bundle extras = getIntent().getExtras();
String phase = extras.getString("phase","enroll");

이렇게 사용도 가능

Bundle extras = getIntent().getExtras();
if (extras != null) {
String phase = extras.getString("phase","enroll");
if (phase.equals("verify")){
//new Handler().postDelayed(Match(),1000);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Match();
}
},1000);
}
}



Posted by 너부리이놈

티스토리 툴바