- Jul 29, 2018
- 7
- 1
Hi Everyone,
I have written a piece of software which is useful for rescaling map-elements with proportional dimensions. The program works by taking-in two vectors as its input, and then producing two equivalent orthonormal vectors (ones that are 1 unit in magnitude and at 90 degrees to each other). These can then be multiplied by any number to resize them, therefore allowing the map-maker to fully control the dimensions of the new object. To run the program, simply download the zip-file and extract the executable; it should ideally be run through Command Prompt. When prompted to type-in the vectors, type-in the elements vertically by pressing "Enter" after each value. For those who use Mac OS or Linux, I have included a copy of the C code for you to compile for your OS. Here is the code:
#include <stdio.h>
#include <math.h>
int main() {
int size, i;
printf("\nHow many dimensions are you working in: ");
scanf("%i", &size);
double A[size], B[size], C[size], D[size], total1, total2, total3, GS_factor;
total1 = 0;
total2 = 0;
total3 = 0;
GS_factor = 0;
printf("\nInsert the first vector's values:\n");
for (i=1;i<=size;i++) {
scanf("%lf", &A[i-1]);
}
printf("\nInsert the second vector's values:\n");
for (i=1;i<=size;i++) {
scanf("%lf", &B[i-1]);
}
for (i=1;i<=size;i++) {
total1 = total1 + pow(A[i-1], 2);
total2 = total2 + pow(B[i-1], 2);
}
total1 = sqrt(total1);
total2 = sqrt(total2);
for (i=1;i<=size;i++) {
C[i-1] = A[i-1]/total1;
}
//Here is where the Gram-Schmidt process occurs
for (i=1;i<=size;i++) {
GS_factor = GS_factor + (B[i-1]*C[i-1]);
}
for (i=1;i<=size;i++) {
D[i-1] = B[i-1] - ((GS_factor)*C[i-1]);
}
for (i=1;i<=size;i++) {
total3 = total3 + pow(D[i-1], 2);
}
for (i=1;i<=size;i++) {
D[i-1] = D[i-1]/sqrt(total3);
}
printf("\nThese are the two orthonormal vectors:");
printf("\nVector 1: Vector 2:");
for (i=1;i<=size;i++) {
printf("\n|%lf| |%lf|", C[i-1], D[i-1]);
}
return 0;
}
I have written a piece of software which is useful for rescaling map-elements with proportional dimensions. The program works by taking-in two vectors as its input, and then producing two equivalent orthonormal vectors (ones that are 1 unit in magnitude and at 90 degrees to each other). These can then be multiplied by any number to resize them, therefore allowing the map-maker to fully control the dimensions of the new object. To run the program, simply download the zip-file and extract the executable; it should ideally be run through Command Prompt. When prompted to type-in the vectors, type-in the elements vertically by pressing "Enter" after each value. For those who use Mac OS or Linux, I have included a copy of the C code for you to compile for your OS. Here is the code:
#include <stdio.h>
#include <math.h>
int main() {
int size, i;
printf("\nHow many dimensions are you working in: ");
scanf("%i", &size);
double A[size], B[size], C[size], D[size], total1, total2, total3, GS_factor;
total1 = 0;
total2 = 0;
total3 = 0;
GS_factor = 0;
printf("\nInsert the first vector's values:\n");
for (i=1;i<=size;i++) {
scanf("%lf", &A[i-1]);
}
printf("\nInsert the second vector's values:\n");
for (i=1;i<=size;i++) {
scanf("%lf", &B[i-1]);
}
for (i=1;i<=size;i++) {
total1 = total1 + pow(A[i-1], 2);
total2 = total2 + pow(B[i-1], 2);
}
total1 = sqrt(total1);
total2 = sqrt(total2);
for (i=1;i<=size;i++) {
C[i-1] = A[i-1]/total1;
}
//Here is where the Gram-Schmidt process occurs
for (i=1;i<=size;i++) {
GS_factor = GS_factor + (B[i-1]*C[i-1]);
}
for (i=1;i<=size;i++) {
D[i-1] = B[i-1] - ((GS_factor)*C[i-1]);
}
for (i=1;i<=size;i++) {
total3 = total3 + pow(D[i-1], 2);
}
for (i=1;i<=size;i++) {
D[i-1] = D[i-1]/sqrt(total3);
}
printf("\nThese are the two orthonormal vectors:");
printf("\nVector 1: Vector 2:");
for (i=1;i<=size;i++) {
printf("\n|%lf| |%lf|", C[i-1], D[i-1]);
}
return 0;
}