合肥工業大學機械人技術作業二

2021-10-17 06:51:45 字數 3236 閱讀 6940

合肥工業大學機械人技術作業二

題目描述:用物件導向的思維設計相關類,從而實現直線與直線、直線與圓、直線與矩形的交點。要求各給出每個案例的至少乙個示例的程式。

演算法思想:1.直線與直線可採用ax+by+c=0來判斷,具體**為:x = (c * otherline.b - b* otherline.c) /(b * otherline.a - a * otherline.b);

2.直線與圓可採用如下**判斷:x1 = -(sqrt((k * k + 1) * cirle.r * cirle.r - c * c * k * k + (2 * c * d + 2 * b * c) * k - d * d - 2 * b * d - b * b) + (b + d) * k + c) / (k * k + 1);

x2 = (sqrt((k * k + 1) * cirle.r * cirle.r - c * c * k * k + (2 * c * d + 2 * b * c) * k - d * d - 2 * b * d - b * b) - (b + d) * k - c) / (k * k + 1);

3.直線與矩形其實就是直線與線段的交點,由計算幾何思想可知只需要滿足線段跨立直線即可,具體實現可以用叉乘或者函式來判斷線段相交.

**實現

//結構定義

//圓class

circle};

//矩形

class

rectangle};

//直線

class

straight

//求交點

void

intersect

(straight otherline)

;void

intersect

(circle cirle)

;void

intersect

(rectangle rectangle);}

;void straight:

:intersect

(straight otherline)

else

}else

}void straight:

:intersect

(circle cirle)

elseif(

this

->b ==0)

else

}void straight:

:intersect

(rectangle rectangle)

elseif(

(-this

->c /

this

->b)

< rectangle.bottomlefty ||(-

this

->c /

this

->b)

> rectangle.toprighty)

else

}cout <<

"直線與矩形兩交點:("

<","<<(-

this

->c /

this

->b)

<<

"),("

<< rectangle.toprightx <<

","<<(-

this

->c /

this

->b)

<<

")"return

;elseif(

this

->b ==0)

elseif(

(-this

->c /

this

->a)

< rectangle.bottomleftx ||(-

this

->c /

this

->a)

> rectangle.toprightx)

else

cout <<

"直線與矩形兩交點:("

<<

-this

->c /

this

->a <<

","<< rectangle.bottomlefty <<

"),("

<<

-this

->c /

this

->a <<

","<< rectangle.toprighty <<

")"<<

return;}

float x1, x2, x3, x4;

float y1, y2, y3, y4;

bool ishvae =

false

;x1 = rectangle.bottomleftx;

y1 =-(

this

->a * x1 +

this

->c)

/this

->b; x2 = rectangle.toprightx;

y2 =-(

this

->a * x2 +

this

->c)

/this

->b; y3 = rectangle.bottomlefty;

x3 =-(

this

->b * y3 +

this

->c)

/this

->a; y4 = rectangle.toprighty;

x4 =-(

this

->b * y4 +

this

->c)

/this

->a;

if(y1 <= rectangle.toprighty && y1 >= rectangle.bottomlefty)

if(y2 <= rectangle.toprighty && y2 >= rectangle.bottomlefty)

if(x3 < rectangle.toprightx && x3 > rectangle.bottomleftx)

if(x4 < rectangle.toprightx && x4 > rectangle.bottomleftx)if(

!ishvae)

cout <<

"無交點"

<< endl; cout << endl;

}//main

intmain()

合肥工業大學oj 1009 紛爭

因為我們不知道訪問這四個b的先後順序,所以我們採取先使用廣度優先搜尋求出b和b之間的距離以及出發點和每個b之間的距離,再根據這些資料建立起乙個節點為五,兩兩之間有邊的無向圖。再對這張圖進行深度優先搜尋即可。include include include include define inf 9999...

合肥工業大學oj 1060 合法棧輸出

其實就是乙個深度優先搜尋,題目的規則就是在某乙個時間你可以選擇執行入棧或出棧,出棧所組成的這些序列就是合法的棧輸出 include includeusing namespace std int n void dfs int,int,string,stack 深度優先搜尋,通過這種方式,可以自然而然地...

jsoup模擬登陸合肥工業大學資訊門戶

合肥工業大學資訊門戶登入介面 開啟f12除錯控制台,登入成功後,發現登陸過程一共跳轉了兩次,請求了兩個檔案 不包括原來登陸介面的檔案 完整 完整 鏈結 儲存cookie值 mapcookies new hashmap 載入驗證碼,獲取cookie,並解析驗證碼 connection connecti...