2016年11月30日 星期三

NSString::取得字串長度(Get NSString Length)


NSString::取得字串長度(Get NSString Length)  

NSString *str1 = @"This is string A";
NSLog(@"Length of str1: %lu", [str1 length]);

執行結果:

2016年9月5日 星期一

C# 已知空間三點,求圓心座標


C#


C# 已知空間三點,求圓心座標

public class PT { public double x { get; set; } public double y { get; set; } public double z { get; set; } }; PT FindCenterPoint(PT pd, PT pd2, PT pd3) { double a1, b1, c1, d1; double a2, b2, c2, d2; double a3, b3, c3, d3; PT pd_center = new PT(); a1 = (pd.y * pd2.z - pd2.y * pd.z - pd.y * pd3.z + pd3.y * pd.z + pd2.y * pd3.z - pd3.y * pd2.z); b1 = -(pd.x * pd2.z - pd2.x * pd.z - pd.x * pd3.z + pd3.x * pd.z + pd2.x * pd3.z - pd3.x * pd2.z); c1 = (pd.x * pd2.y - pd2.x * pd.y - pd.x * pd3.y + pd3.x * pd.y + pd2.x * pd3.y - pd3.x * pd2.y); d1 = -(pd.x * pd2.y * pd3.z - pd.x * pd3.y * pd2.z - pd2.x * pd.y * pd3.z + pd2.x * pd3.y * pd.z + pd3.x * pd.y * pd2.z - pd3.x * pd2.y * pd.z); a2 = 2 * (pd2.x - pd.x); b2 = 2 * (pd2.y - pd.y); c2 = 2 * (pd2.z - pd.z); d2 = pd.x * pd.x + pd.y * pd.y + pd.z * pd.z - pd2.x * pd2.x - pd2.y * pd2.y - pd2.z * pd2.z; a3 = 2 * (pd3.x - pd.x); b3 = 2 * (pd3.y - pd.y); c3 = 2 * (pd3.z - pd.z); d3 = pd.x * pd.x + pd.y * pd.y + pd.z * pd.z - pd3.x * pd3.x - pd3.y * pd3.y - pd3.z * pd3.z; pd_center.y = (a1 * c2 * d3 - a1 * c3 * d2 - a2 * c1 * d3 + a2 * c3 * d1 + a3 * c1 * d2 - a3 * c2 * d1) / (a1 * b2 * c3 - a1 * b3 * c2 - a2 * b1 * c3 + a2 * b3 * c1 + a3 * b1 * c2 - a3 * b2 * c1); pd_center.z = -(a1 * b2 * d3 - a1 * b3 * d2 - a2 * b1 * d3 + a2 * b3 * d1 + a3 * b1 * d2 - a3 * b2 * d1) / (a1 * b2 * c3 - a1 * b3 * c2 - a2 * b1 * c3 + a2 * b3 * c1 + a3 * b1 * c2 - a3 * b2 * c1); pd_center.x = -(b1 * c2 * d3 - b1 * c3 * d2 - b2 * c1 * d3 + b2 * c3 * d1 + b3 * c1 * d2 - b3 * c2 * d1) / (a1 * b2 * c3 - a1 * b3 * c2 - a2 * b1 * c3 + a2 * b3 * c1 + a3 * b1 * c2 - a3 * b2 * c1); return pd_center; }



2016年7月11日 星期一

Objective Static


Objective Static


靜態變數預設的初始值為0,且執行期間只會被初始一次,以下使用Static關鍵字實現方法呼叫次數

@interface Page: NSObject -(void) showTimes; @end @implementation Page -(void) showTimes { static int PageTimes; ++PageTimes; NSLog(@"showTimes Call Times : %i", PageTimes); } @end int main(int argc, const char * argv[]) { @autoreleasepool { Page *myPage = [Page new]; [myPage showTimes]; Page *myPage2 = [Page new]; [myPage2 showTimes]; Page *myPage3 = [Page new]; [myPage3 showTimes]; } return 0; }



2016年5月10日 星期二

Linux硬碟裝置的認定

Linux硬碟裝置認定

  1. IDE裝置:
        以 hd 作為開頭,英文a、b、c、d排序。在傳統的主機板上,通常有兩個IDE排線插孔,每個排線可插兩顆硬碟或光碟。第一個IDE排線上的第一個裝置為/dev/hda,第二個裝置為/dev/hdb;第二個IDE排線上的第一個裝置為/dev/hdc,第二個裝置為/dev/hdd。
        分割硬碟依數字命名,/dev/hda1、/dev/hda2、/dev/hda3。
  2. SCSI、SATA與USB裝置:
        以 sd 作為開頭,英文a、b、c、d排序。第一個裝置為/dev/sda,第二個裝置為/dev/sdb,第三個裝置為/dev/sdc⋯⋯ 。
        分割硬碟依數字命名,/dev/sda1、/dev/sda2、/dev/sda3。