Professional Documents
Culture Documents
2D Projection on
the flat surface
3D Object
Different 2D
projections of
the same can
be created
3D Point {X,Y,Z} 2D Projection Point {Xp, Yp}
Types of 3D Projections
Rays converge on eye position Rays parallel
Perspective Parallel
Rays at angle to view plane
Orthographic Oblique
Isometric
Parallel Projection
Cavalier Oblique ( ) ֲאלַכְ סֹונִ יProjection
From Math to Code
(Cavalier Oblique
Projection)
Simplest Example: Cube
Set of 3D Points {X,Y,Z} to Set of 2D Projection Points {Xp, Yp}
Hidden Line and Surface Removal Algorithms:
More realistic imaging
Z-Buffer Algorithm for hidden lines/points removal
Simplest and slowest + holes possible
float zBuffer[NumOfRows][NumOfColumns];
uchar byteGrayImage [NumOfRows][NumOfColumns];
Fill zBuffer with zeroes (or with non realistic negative numbers}
Fill byteGrayImage with zeroes {or with other background value}
For each 3D point {X,Y,Z, PoinColor} calculate {Xp, Yp}
If zBuffer[Yp][Xp] < Z
{
zBuffer[Yp][Xp] = Z
byteGrayImage[Yp][Xp] = PoinColor;
}
Projection parameters: a and f
Complex 3D Objects
3D Mesh (Education: Math, CNC)
Types of Oblique Projection: Cavalier & Cabinet Projections
Small letters:
It’s time to write some code (C#, .NET)
(well explore “example”)
To work from home Download free
Microsoft Visual C# 2013 Express Edition
Steps:
1 3
5
4
8
7
6
New Project created: Main VS Elements
1. Solution (Project) Explorer:
All project files in an organized manner
2. Form
- Place for “controls”,
texts, images, etc…
2. Yes,
Do Very smart rename
(refactor)
VS do a lot of work… Nearly everything is ImProc now..
Start Program/Procedure
Wait for user input User “suddenly” typed
Call Function #1 “Alt-Ctrl_Del”
Call Function #2
Wait for user input Interrupt (Stop/Halt)
Call Function #3 “normal program flow”
…
Return to caller Goto “specially” written function
(Event/Interrupt Handler)
Do what is written there
(for example: burn the hard disk )
Event (Interrupt)
and Event (Interrupt) Handler
Windows Application:
Event Handler:
Specially Written Function
1. Click here
2. Click here
DrawArc
DrawBezier
DrawClosedCurve
DrawCurve
DrawEllipse (No need for DrawCircle !!!)
DrawImage (Used in Image Processing)
DrawLine
DrawPie
DrawPolygon
DrawRectangle
DrawString
Download source:
…\3D Draw
Add parameters /variables : Type “Green”
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ImProc
{
public partial class ImProc : Form
{
Pen pen = new Pen(Color.Black);
float alphaInRadians = (float)Math.PI / 4;
float phiInRadians = (float)Math.PI / 6;
float Xp1 = 0;
float Yp1 = 0;
float Xp2 = 0;
float Yp2 = 0;
public ImProc()
{
InitializeComponent();
}
Write function “CalculateProjection”
public Form1()
{
InitializeComponent();
}
}
Write Function: “Draw3dLine”
By Using “Properties”
Select ImProc form. Set AutoScroll True
Alpha Phi
Minimum 0 179
Maximum 0 360
SmallChange 1
Value 45 45
Set Location and Sizes
By Using “Properties”
Select drawingPanel
Set Location {10,10}
Set Size {640,480}
Select guiPanel
Set Location {10,500}
Set Size {640, 130}
Intermediate Appearance
(GUI do nothing for now)
Modify “constructor”
public ImProc()
{
InitializeComponent();
alphaTrackBar.Value = 45;
phiTrackBar.Value = 45;
alphaLabel.Text = "Alpha: " +
alphaTrackBar.Value.ToString();
phiLabel.Text = "Phi: " +
phiTrackBar.Value.ToString();
}
Modify “CalcProjection”
private void CalcProjection(
float X, float Y, float Z,
ref float Xp, ref float Yp)
{
float alphaInRadians =
alphaTrackBar.Value * 2 * (float)Math.PI / 360;
float phiInRadians =
phiTrackBar.Value * 2 * (float)Math.PI / 360;
float L;
if (alphaInRadians == 0)
{
L = 0;
}
else
{
L = Z / (float)Math.Tan(alphaInRadians);
}
if (projectionType == eProjectionType.Cabinet)
{
L = L / 2;
}
Xp = (float)(X + L * (float)Math.Cos(phiInRadians));
Yp = (float)(Y - L * (float)Math.Sin(phiInRadians));
}
Add Event Handlers for the Track Bars
3. Type “onAlphaTrackBarScroll”
And double click
2. Click
1. Click
Add Code for Event Handlers for the Track Bars
At THIS MOMENT
private void CalcProjection( Request value of the track bar,
float X, float Y, float Z, Convert it and use for the
ref float Xp, ref float Yp) “calculations”
{
float alphaInRadians =
alphaTrackBar.Value * 2 * (float)Math.PI / 360;
float phiInRadians =
phiTrackBar.Value * 2 * (float)Math.PI / 360;
float L;
if (alphaInRadians == 0)
{
L = 0;
}
else
It is work now !!! But HOW ???
(How event-driven software behave)
Return to Draw3DLine
private void Draw3DLine(Graphics gr,
float X1, float Y1, float Z1,
float X2, float Y2, float Z2)
{
CalcProjection(X1, Y1, Z1,
ref Xp1, ref Yp1);
Draw on the Graphics You
CalcProjection(X2, Y2, Z2, have got from Paint
ref Xp2, ref Yp2);
}
Return to Windows Event Loop and
wait for the next
UNPREDICTABLE
user’ input
Next Job to do
(Details later)