[3d] 삼각형과 광선 교차알고리즘

Real-Time Rendering의 13.7.1 교차알고리즘에서..

아래 소스는 cpp소스임.

Vec3는 벡터3 클래스임.


// o : 광선 원점
// d : 광선 방향
// v0, v1, v2 : 삼각형 3점
// pp : 교차점 반환 (true일때만)
bool rayTriIntersect(const Vec3& o, const Vec3& d, const Vec3& v0, const Vec3& v1, const Vec3& v2, Vec3& pp) {

    Vec3 e1 = v1 – v0;
    Vec3 e2 = v2 – v0;
   
    Vec3 dd = d;
    Vec3 p = dd.cross( e2 );
   
    GLfloat det = e1.dot( p );
   
    if( det > -EPSILON && det < EPSILON )
        return false;
   
    GLfloat invDet = 1.0f / det;
   
    Vec3 s = o – v0;
   
    GLfloat u = s.dot( p ) * invDet;
   
    if( u < 0.f || u > 1.f )
        return false;
   
    Vec3 q = s.cross( e1 );
    GLfloat v = dd.dot( q ) * invDet;
   
    if( v < 0.f || (u + v) > 1.f )
        return false;
   
    GLfloat t = e2.dot( q ) * invDet;

    pp = (1-u-v)*v0 + u*v1 + v*v2;
    return true;
}

[oracle] split function

오라클에서 a,b,c,d 같은 문자열으르 테이블 형식으로 뽑아주는 함수를 만들 수 있다.
type은 전역적으로 지정되어야 한다.

IN (‘a’, ‘b’, ‘c’) 등을 바인드로 사용할 수 있다.

SQL> create or replace type myArray as table of number
2 /

Type created.

SQL>
SQL> create or replace function str2table( p_string in varchar2 )
return myArray
2 as
3 l_data myArray := myArray();
4 l_string long := p_string;
5 l_n number;
6 begin
7 while (l_string is not null)
8 loop
9 l_n := instr( l_string, ‘;’ );
10 if ( l_n = 0 )
11 then
12 l_n := length(l_string)+1;
13 end if;
14 l_data.extend;
15 l_data(l_data.count) := substr( l_string, 1,
l_n-1 );
16 l_string := substr( l_string, l_n+1 );
17 end loop;
18 return l_data;
19 end;
20 /

Function created.

SQL> select * from TABLE ( str2table(’12; 15; 8′) );

COLUMN_VALUE
————
12
15
8


참고 : http://www.groupsrv.com/computers/post-1517533.html

[oracle] insert all

Oracle 9i 이상에서 지원 됩니다.

 

— Unconditional insert into ALL tables                                
INSERT ALL                                                             
  INTO sal_history VALUES(empid,hiredate,sal)                          
  INTO mgr_history VALUES(empid,mgr,sysdate)                           
SELECT employee_id EMPID, hire_date HIREDATE, salary SAL, manager_id MGR
  FROM employees WHERE employee_id > 200;                              
                                                                       
— Pivoting insert to split non-relational data                        
INSERT ALL                                                             
  INTO Sales_info VALUES (employee_id,week_id,sales_MON)               
  INTO Sales_info VALUES (employee_id,week_id,sales_TUE)               
  INTO Sales_info VALUES (employee_id,week_id,sales_WED)               
  INTO Sales_info VALUES (employee_id,week_id,sales_THUR)              
  INTO Sales_info VALUES (employee_id,week_id, sales_FRI)              
SELECT EMPLOYEE_ID, week_id, sales_MON, sales_TUE,                     
    sales_WED, sales_THUR,sales_FRI                                    
FROM Sales_source_data;                                                
                                                                       
— Conditionally insert into ALL tables                                
INSERT ALL                                                             
  WHEN SAL>10000 THEN                                                  
    INTO sal_history VALUES(EMPID,HIREDATE,SAL)                        
  WHEN MGR>200 THEN                                                    
    INTO mgr_history VALUES(EMPID,MGR,SYSDATE)                         
SELECT employee_id EMPID, hire_date HIREDATE, salary SAL, manager_id MGR
  FROM employees WHERE employee_id > 200;                               
                                                                       
— Insert into the FIRST table with a matching condition               
INSERT FIRST                                                           
  WHEN SAL > 25000  THEN                                               
    INTO special_sal VALUES(DEPTID,SAL)                                
  WHEN HIREDATE like (‘%00%’) THEN                                     
    INTO hiredate_history_00 VALUES(DEPTID,HIREDATE)                   
  WHEN HIREDATE like (‘%99%’) THEN                                     
    INTO hiredate_history_99 VALUES(DEPTID,HIREDATE)                   
  ELSE                                                                 
    INTO hiredate_history VALUES(DEPTID, HIREDATE)                     
SELECT department_id DEPTID, SUM(salary) SAL,                          
    MAX(hire_date) HIREDATE                                            
  FROM employees GROUP BY department_id;        

[oracle] split in oracle


데이타가 a,b,c,d,e 이런 형식일때.. 특수문자는 오데이타가 나오므로 특수문자 치환필요


 


       SELECT substr(wdata,
                      instr(wdata, ‘,’, 1, LEVEL) + 1,
                      instr(wdata, ‘,’, 1, LEVEL + 1) – instr(wdata, ‘,’, 1, LEVEL) – 1) user_id
          FROM (SELECT ‘,’ || REPLACE(worker_id, ‘┍’, ‘,’) || ‘,’ wdata
                  FROM maxiemweb.fms_job_orders
                 WHERE ticket_step_seq = ‘TSTP20080218004265’)
        CONNECT BY LEVEL <= length(wdata) – length(REPLACE(wdata, ‘,’)) – 1


[cpp] BigInteger class in cpp

 Big Integer 를 표현하기에 적합한 C++에서의 클래스

http://mattmccutchen.net/bigint/index.html

에서 받아서 사용하면 되고, sample 페이지가 있으니 참고..

string에서 radix의 편한 사용을 위해서

BigIntegerUtils.h

std::string bigUnsignedToString(const BigUnsigned &x, int base=10);
std::string bigIntegerToString(const BigInteger &x, int base=10);
BigUnsigned stringToBigUnsigned(const std::string &s, int base=10);
BigInteger stringToBigInteger(const std::string &s, int base=10);

BigIntegerUtils.cpp

std::string bigUnsignedToString(const BigUnsigned &x, int base) {
    return std::string(BigUnsignedInABase(x, base));
}

std::string bigIntegerToString(const BigInteger &x, int base) {
    return (x.getSign() == BigInteger::negative)
        ? (std::string(“-“) + bigUnsignedToString(x.getMagnitude(), base))
        : (bigUnsignedToString(x.getMagnitude(), base));
}

BigUnsigned stringToBigUnsigned(const std::string &s, int base) {
    return BigUnsigned(BigUnsignedInABase(s, base));
}

BigInteger stringToBigInteger(const std::string &s, int base) {
    // Recognize a sign followed by a BigUnsigned.
    return (s[0] == ‘-‘) ? BigInteger(stringToBigUnsigned(s.substr(1, s.length() – 1), base), BigInteger::negative)
        : (s[0] == ‘+’) ? BigInteger(stringToBigUnsigned(s.substr(1, s.length() – 1), base))
        : BigInteger(stringToBigUnsigned(s, base));
}


이부분을 수정하면 radix를 편하게 사용할 수 있다.