473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

line drawing

1
I need to know the midpoint line drawing program to draw lines in all the eight directions.
Sep 17 '06 #1
1 5530
D_C
293 100+
I assume that all eight lines will have the same distance, and all have one end at the endpoint. Further, that each line will be 45º from the two closest lines.


Let r = sqrt(32). Assume that I pass (r,0) and (-r,0) as the co-ordinates. Then the other coordinates should be (0,r), (0,-r), and all four possibilities of (±4,±4).

If that's the case, here's what to do.
1. Find the midpoint. The x- and y-coordinates are the averages of the two x- and y-coordinates, respectively. For the example of (r,0) and (-r,0), they average to (0,0).
Expand|Select|Wrap|Line Numbers
  1. Xavg = (X1+X2)/2;
  2. Yavg = (Y1+Y2)/2;
2. Consider a line from the midpoint to either point. Describe it in polar coordinates. Let (X,Y) be either (X1,Y1) or (X2,Y2).
Expand|Select|Wrap|Line Numbers
  1. r = sqrt((X-Xavg)^2 + (Y-Yavg)^2);
  2. theta = arctan((Y-Yavg)/(X-Xavg));
3. Rotate the line by multiples of 45 degrees, which is simple to do in polar coordinates. Do a loop that goes from 0 to 7, but not 8. Then calculate a temporary theta, and derive new coordinates. r stays the same.
Expand|Select|Wrap|Line Numbers
  1. for(i = 0; i < 8; i++)
  2. {
  3.   new_theta = theta + 45*(i);
  4.   new_X = r*cos(new_theta);
  5.   new_Y = r*sin(new_theta);
  6.   // Draw line from (Xavg,Yavg) to (new_X,new_Y)
  7. }
Sep 17 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: C. Alexander | last post by:
I'm making a 'whiteboard' application. I'm trying to have 2+ connected users able to draw at the same time. However, if User1 draws a line, when User2 is drawing, on User1 screen, it will draw...
1
by: Dennis | last post by:
I started a new thread because i cant reply on the older one. Thank you very much Rick for the usefull reply. But i'v got another question. When drawing the line, you cant see the line untill you...
0
by: Tomi Holger Engdahl | last post by:
I am looking for a solution to add on-line drawing tool to a phpBB discussion board. The idea would be that the users can draw their own simple drawings with the tool and attach them easily as...
9
by: Steve Long | last post by:
Hello, (total GDI newbie) I'm having trouble drawing just a simple line to display in a picturebox. I just want a straight, dotdash line. I have two methods, one works and one doesn't (it cause...
6
by: Rene | last post by:
I tried searching the newsgroups to see how do you draw a dotted line but I was unable to find an answer, drawing a straight line is very easy but not a dotted one. So the question is, how do I...
4
by: Mathieu Chavoutier | last post by:
Hi. I would like to do something like paint. I try to draw a line. I want, like paint, that when I clickdown, it begins to draw the line, and then, when I move the mouse, the line follow the...
2
by: Martijn Mulder | last post by:
I want to know if the mouse is over (hitting) a line. Therefore I created a Region object that holds the line and use the IsVisible() method to test if the mouse hits the line. It doesn't work! In...
13
by: Martijn Mulder | last post by:
I try to define a line with the length of 1 unit (1 pixel) that is, in fact, just a point on the screen. But when I draw it with a wide pen with the appropriate StartCap and EndCap (Round), it will...
2
by: mattc66 via AccessMonster.com | last post by:
Does anyone know of some simple line drawing add-on apps. I just need to be able to do some simple line drawing with dims. 4 walls and a door and allow the user to type the dims for the walls. All...
5
by: Macias | last post by:
Hi, Please help me, how I can make a line drawing on PictureBox similar to MS paint. I thinking about this: click and hold button, move mouse and relase button. I'm trying useing this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.