Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-18-2005, 09:49 AM   #1 (permalink)
Cyn
Registered User
 
Join Date: Feb 2005
Posts: 2
Cyn is on a distinguished road
Unhappy Help

Hi i have an assignment i have to write a program that draws a line across +ve and -ve axes. i used the DDA line algorithm but i don't know how to implement it such that i can draw my line in the -ve quadrants. For the time being My line can only be +ve. Can n e one help me please?
Cyn is offline   Reply With Quote
Old 02-18-2005, 08:44 PM   #2 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Well remember the reason you have an assignement is to learn to solve the problem yourself, but often explaing the problem properly will set things straight in your brain so why don't you explain the problem in more detail, particularly the DDA line algorithm and the ve- and ve+ axes.
teknomage1 is offline   Reply With Quote
Old 02-19-2005, 05:46 AM   #3 (permalink)
Cyn
Registered User
 
Join Date: Feb 2005
Posts: 2
Cyn is on a distinguished road
my problem is that i don't know how the code to write if i want my line to be in 2nd, 3rd or 4th quadrant.
Cyn is offline   Reply With Quote
Old 02-19-2005, 07:52 AM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
Oh come on. You can do DDA. Even I needed only 2 minutes of study. This is the result:
Code:
#include <iostream>

using namespace std;

void DDA(int x1,int y1,int x2, int y2)
{
  int length;
  double x,y;
  double xIncr, yIncr;

  length = abs(x2 - x1);
  if (abs(y2 - y1) > length)
  {
    length = abs(y2 - y1);
  }
  xIncr = (double)(x2 - x1)/(double)length;
  yIncr = (double)(y2 - y1)/(double)length;
  x = x1 + 0.5;
  y = y1 + 0.5;
  while(length)
  {
    cout<<(int)x<<", "<<(int)y<<endl;
    x += xIncr;
    y += yIncr;
    --length;
  }
}

int main(int argc, char *argv[])
{
  DDA(-5, -3, 5, 9);
  
  cin.get();
  return 0;
}
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 08:22 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting