본문 바로가기

분류 전체보기

GIS/ TM 좌표계를 경위도 좌표계로 변환하는 방법

2020. 4. 8.

TM 좌표를 WGS84로 변환하는 엑셀 수식입니다.

 

국토지리정보원에서 제공하는 표준 정보를 이용해서 만든 자료입니다.

 

링크:  https://autoc.tistory.com/315

 

경위도 ↔ TM 좌표 변환

경위도 ↔ TM 좌표를 변환할 일이 있는데 손쉽게 사용할 프로그램이 없어 직접 만들게되었습니다. 도로 배수시설 설계 및 관리지침(2012.11, 국토교통부)에 따라 임의 지점의 경위도 값을 이용하여 강우강도 산출..

autoc.tistory.com

 

댓글

C++/ 병렬처리에서 std::vector의 push_back() 사용하기

2020. 3. 3.

std::vector의 push_back() 함수를 사용하면 충돌현상이 발생함

 

1. 따라서 push_back()이 발생할 때 아래처럼 처리하면 push_back()의 효과를 낼 수 있음

output.resize(input.rows);
int k = 0;

#pragma omp parallel for shared(k, input)
for( int i = 0; i < input.rows; i++ )
{
    if(IsGoodMatch(input[I])
    { 
        Newvalues newValues;
        ...
        // ! prevent other threads to modify k !
        output[k] = newValues;
        k++;
        // ! allow other threads to modify k again !
    }
} 

output.resize(k);

 

2. 또는 멀티 쓰레드 처리를 위해 개발된 concurrency vector의 push_back()을 사용하면 됨

#include <concurrent_vector.h>
Concurrency::concurrent_vector<int> // in c++11.

 

https://stackoverflow.com/questions/19268217/stdvector-push-back-fails-when-used-in-a-parallel-for-loop

 

std::vector push_back fails when used in a parallel for loop

I have a code that is as follow (simplified code): for( int i = 0; i < input.rows; i++ ) { if(IsGoodMatch(input[I]) { Newvalues newValues; newValues.x1=input.x1;

stackoverflow.com

 

댓글

C++/ 함수 내에 매크로 함수 정의 및 사용하기

2020. 3. 3.
void func1() 
{
    #define update_leftmost(i) \
    { \
        const vec2_t &p  = polygon[i];                                   \
        const vec2_t &lm = polygon[iLeftMost];                           \
        if (p.x < lm.x || (p.x == lm.x && p.y < lm.y)) iLeftMost = i;    \
    }
    
    #define init_vertex(i, iPrev, iNext) \
        vertices[i].index = i;                                           \
        vertices[i].prev = &vertices[iPrev];                             \
        vertices[i].next = &vertices[iNext];                             \
        vertices[i].prev->index = iPrev;                                 \
        vertices[i].next->index = iNext;                                 \
        vertices[i].winding_value = winding_value(polygon, vertices[i]); \
        vertices[i].reflex = false;

    // initialize vertices

    init_vertex(0    , N - 1, 1);
    init_vertex(N - 1, N - 2, 0);

    update_leftmost(N - 1);

    for (int i = 1; i < N - 1; i++)
    {
        init_vertex(i, i - 1, i + 1);
        update_leftmost(i);
    }
}
댓글

알고리즘/ 한 점과 직선 사이의 거리 계산

2020. 3. 2.

Distance from a point to a line/segment

 

// 일반 함수
/* 점과 직선 사이의 거리 계산 */
static std::array<int, 3> cross(const std::array<int, 3> &a,
	const std::array<int, 3> &b)
{
	std::array<int, 3> result;
	result[0] = a[1] * b[2] - a[2] * b[1];
	result[1] = a[2] * b[0] - a[0] * b[2];
	result[2] = a[0] * b[1] - a[1] * b[0];
	return result;
}

static double point_to_line_distance(const cv::Point &p, const cv::Vec4i &line)
{
	std::array<int, 3> pa{ { line[0], line[1], 1 } };
	std::array<int, 3> pb{ { line[2], line[3], 1 } };
	std::array<int, 3> l = cross(pa, pb);
	return std::abs((p.x * l[0] + p.y * l[1] + l[2])) * 1.0 /
		std::sqrt(double(l[0] * l[0] + l[1] * l[1]));
}

// 또는

// 템플릿 함수화
template<typename point3_t>
point3_t cross(const point3_t vec1_pos, const point3_t vec2_pos)
{
	return point3_t(
		vec1_pos.y * vec2_pos.z - vec1_pos.z * vec2_pos.y,
		vec1_pos.z * vec2_pos.x - vec1_pos.x * vec2_pos.z,
		vec1_pos.x * vec2_pos.y - vec1_pos.y * vec2_pos.x);
}
    
/* 점과 직선 사이의 거리 계산 */
template <typename point2_t, typename vec4_t>
double point_to_line_distance(const point2_t &p, const vec4_t &line)
{
	struct point3_d { double x, y, z; point3_d() {}; point3_d(double a, double b, double c) { x = a; y = b; z = c; }; };
	point3_d line_s(line[0], line[1], 1);
	point3_d line_e(line[2], line[3], 1);
	point3_d line_parameters = cross(line_s, line_e);	// line_parameters[3] mean {a, b, c} of line equation(ax + by + c = 0).
	return std::abs((line_parameters.x * p.x + line_parameters.y * p.y + line_parameters.z)) * 1.0 / std::sqrt(double(line_parameters.x * line_parameters.x + line_parameters.y * line_parameters.y));
}

 

https://stackoverflow.com/questions/12132352/distance-from-a-point-to-a-line-segment

 

Distance from a point to a line/segment

I have to compute the distance from a point to a line (check if it is line or a line segment). I am not sure that the bool function IsSegment is working properly. Can i have some suggestions? Thank...

stackoverflow.com

 

댓글

C++/ 동적으로 배열 할당하기

2020. 2. 27.

C++ 07.13 - 동적으로 배열 할당하기 (Dynamically allocating arrays)
https://boycoding.tistory.com/205

 

C++ 07.13 - 동적으로 배열 할당하기 (Dynamically allocating arrays)

동적으로 배열 할당하기 (Dynamically allocating arrays) 단일 변수에 대한 동적 할당뿐만 아니라 배열 변수를 동적 할당할 수 있다. 컴파일 타임에 배열 길이를 정하는 고정 배열(fixed array)과 다르게 배열을..

boycoding.tistory.com

 

댓글

Debug/ error LNK2005: already defined function

2020. 2. 27.

헤더파일에 작성한 문법에 이상이 없는 함수 코드가 빌드되지 않고 error LNK2005 가 발생할 때는,

static 이나 inline 함수로 선언한다.

 

Some possible solutions are:

  1. Declare the functions as static, which implies internal linkage
  2. Inline the functions
  3. Move the implementation out of the header and into a c/c++ file

Read more here: What is external linkage and internal linkage?

 

 

https://stackoverflow.com/questions/6964819/function-already-defined-error-in-c

 

Function already defined error in C++

I have a file called "SimpleFunctions.h" defined as follow: #ifndef SIMPLEFUNCTIONS_H #define SIMPLEFUNCTIONS_H namespace my_namespace { double round(double r) { return (r > 0.0) ? floor(r + ...

stackoverflow.com

 

댓글

알고리즘/ 3차원 배열의 인덱스를 1차원으로 변환하기

2020. 2. 27.

3차원 영상(공간?) 도메인에서 3차원 배열의 인덱스를 1차원으로 변환하는 식은 아래와 같음

public int to1D( int x, int y, int z ) {
    return (z * xMax * yMax) + (y * xMax) + x;
}

public int[] to3D( int idx ) {
    final int z = idx / (xMax * yMax);
    idx -= (z * xMax * yMax);
    final int y = idx / xMax;
    final int x = idx % xMax;
    return new int[]{ x, y, z };
}

https://stackoverflow.com/questions/7367770/how-to-flatten-or-index-3d-array-in-1d-array

 

How to "flatten" or "index" 3D-array in 1D array?

I am trying to flatten 3D array into 1D array for "chunk" system in my game. It's a 3D-block game and basically I want the chunk system to be almost identical to Minecraft's system (however, this i...

stackoverflow.com

 

댓글