# 3D Projection Vol. 2 © LGPL

This project uses axonometric projection for more accurate 3D.

• 432 views
• 1 respect

## Components and supplies

 Arduino Micro & Genuino Micro
×1
 SeeedStudio Seeed TFT Touch Screen
×1
 Texas Instruments 74HC595
×1

### 3D Projection

3D Projection is any method of mapping three-dimensional points to a two-dimensional plane. As most current methods for displaying graphical data are based on planar two-dimensional media, the use of this type of projection is widespread, especially in computer graphics and engineering.

### Axonometric Projection

Axonometric projection is a type of parallel projection used for creating a pictorial drawing of an object, where the object is rotated along one or more of its axes relative to the plane of projection. There are three main types of axonometric projection: isometric, dimetric, and trimetric projection. "Axonometric" means "to measure along axes". Axonometric projection shows an image of an object as viewed from a skew direction in order to reveal more than one side in the same picture. Whereas the term orthographic is sometimes reserved specifically for depictions of objects where the axis or plane of the object is parallel with the projection plane, in axonometric projection the plane or axis of the object is always drawn not parallel to the projection plane.

With axonometric projections the scale of distant features is the same as for near features, so such pictures will look distorted, as it is not how our eyes or photography work. This distortion is especially evident if the object to view is mostly composed of rectangular features. Despite this limitation, axonometric projection can be useful for purposes of illustration.

### Window to viewport coordinate transformation

A world-coordinate area selected for display is called a window. An area on a display device to which a window is mapped is called a viewport. The window defines what is to be viewed; the viewport defines where it is to be displayed.

The window-to-viewport mapping. A point at position (xw, yw) in the window is mapped into position (xv, yv) in the associated viewport. To maintain the same relative placement in the viewport as in the window, we require that

``````xv - xvmin / xvmax - xvmin = xw - xwmin / xwmax - xwmin
yv - yvmin / yvmax - yvmin = yw - ywmin / ywmax - ywmin
``````

Solving these expressions for the viewport position (xv, yv), we have Ecuation A

``````xv = xvmin + (xw - xwmin)sx<_e_0chM>yv = yvmin + (yw - ywmin)sy
``````

where the scaling factors are:

``````sx = xvmax - xvmin / xwmax - xwmin
sy = yvmax - yvmin / ywmax - ywmin
``````

Equations A can also be derived with a set of transformations that converts the window area into the viewport area. This conversion is performed with the following sequence of transformations:

1. Perform a scaling transformation using a fixed-point position of (xwmin, ywmin) that scales the window area to the size of the viewport.

2. Translate the scaled window area to the position of the viewport. Relative proportions of objects are maintained if the scaling factors are the same (sx = sy). Otherwise, world objects will be stretched or contracted in either the x or y direction when displayed on the output device.

### The Focal Length

In optics, this word is defined as the distance from the lens node to the point at which a ray, which was initially parallel to the optical axis, intercepts the axis after being deflected by the lens. The focal length is given by:

``````Fl = p x q  / p + q
``````

### Rendering

This is the process of producing an image based on three-dimensional data stored within a computer. 3D rendering is a creative process that is similar to photography or cinematography, because you are lighting and staging scenes and producing images.

The three dimensional data that is reproduce could be a complete scene including geometric models of different three dimensional objects, buildings, landscapes, and animated characters - artists need to create this scene by modeling and animating before the rendering can be done. The 3D rendering process depicts this three-dimensional scene as a picture, taken from a specified location and perspective.

Rendering sometimes takes a long time, even on very fast computers. This is because the software is essentially "photographing" each pixel of the image.

## Code

##### ATmega32u4_3DProjection.inoArduino
```/*
*	Author		: Zavala Ortiz Vicente Arturo.
*	language	: .ino
*	Date		: 4/25/2013 2:51:45 PM
*	Name		: ATmega32u4_3DProjection.ino
*	Description : 3D projection
*/

#include <avr/io.h>
#include <avr/pgmspace.h>

#include "TFT.h"
#include "3D_Math.h"

void init_prespective(double Psi, double Theta, double Phi, double rotPsi, double rotTheta, double rotPhi);
void cube_3D();

UBYTE SHAPE			= 20;

VECTOR_3D pts3D;
double Psi, Theta, Phi, rotPsi, rotTheta, rotPhi;

volatile uint8_t INT_BITS;
uint8_t option;

void setup()
{
/* add setup code here */
Tft.init();

3D.setViewport(-4, 4, -3, 3, 0, 200, 50, 250);
init_prespective(Psi, Theta, Phi, rotPsi, rotTheta, rotPhi);

Psi			= 75;
Theta		= 0;
Phi			= 165;
rotPsi		= Psi;
rotTheta	= Theta;
rotPhi		= Phi;

cli();
// Enable external pin interrupts
set_bit_port(PCICR, PCIE0);
set_bit_port(PCMSK0, PCINT4);
set_bit_port(PCMSK0, PCINT5);
set_bit_port(PCMSK0, PCINT6);
sei();
}

void loop()
{
/* add main program code here */
if(INT_BITS != 0)
{
Tft.clrscr();

switch(option)
{
case 0x10:
if((Psi += 25) > 360) Psi = 0.0;
break;

case 0x20:
if((Theta += 25) > 360) Theta = 0.0;
break;

case 0x40:
if((Phi += 25) > 360) Phi = 0.0;
break;
}

init_prespective(Psi, Theta, Phi, rotPsi, rotTheta, rotPhi);

switch(SHAPE)
{
case 10 :
break;

case 20 :
cube_3D();					// Cube
break;

case 30 :
Sphere_3D();        // Sphere
break;

case 40 :
Torus_3D();         // Torus
break;
}
}
}

ISR(PCINT0_vect)
{
if((INT_BITS = (PINB & KEYBOARD_MASK))) {
option = INT_BITS;
_delay_ms(5);			// Switch debounce
}
}
```

• 11 projects
• 18 followers

March 15, 2017

#### Members who respect this project

See similar projects
you might like

#### KITtyBot

Project tutorial by StaffanEk

• 2,092 views
• 1 comment
• 8 respects

#### Measure and Analyze Tide Levels with ThingSpeak and MATLAB

Project tutorial by Team MATLAB IoT

• 3,825 views
• 19 respects

#### Drive with PID Control on an Arduino Mega 2560

Project tutorial by Team MATLAB Makers

• 3,298 views
• 8 respects

#### Helping the Disabled and Chronic Patients battle the heat

Project tutorial by Manan Rai

• 662 views
• 6 respects

#### CUTSIE WHUN Version 2 - The Ultimate Balancing Robot

Project in progress by Pigeon-Kicker

• 294 views