diagramming problem 
Author Message
 diagramming problem

I am wondering if anyone can help me.

I am writing a program that models business processes.  It has an interface
similar to Rational Rose (Visual Modeler).  I would like to be able to draw
a connection between two objects.

for example:

----------                ----------                ----------
|   A     |-------------|   B     |         or    |   A    |
----------                ----------                ----------
                                                               |
                                                               |
                                                         ----------
                                                         |    B    |
                                                         ----------

The connection should be from the edge of A to the edge of B using the edges
of the objects closest to each other.  All this is based on a straight line
from the center of A to the center of B.  Drawing a line from the center of
A to the Center of B is no problem.  The problem arises from drawing the
line only to the EDGE of each object.

I cannot figure out a nice algorithm to figure out which edge to use. I also
need to know exactly where along the edge to start the line. For example if
object A is down and left relative to object B then by looking at the
picture I know that the line should be drawn from the top edge of A about
two thirds of the way to the right to the bottom edge of B about one third
of the way from the left.

If anyone has any ideas I would really appreciate the help.

Thank You.

Simon Forman

Please note: my email address has been "spam proofed" remove  the DELETETHIS
part when replying.



Tue, 14 Aug 2001 03:00:00 GMT  
 diagramming problem
Why don't you use free hidden line removal.

1. Draw line from box A centre to Box B centre.
2. Draw boxes. ( with non transparent white inside )

No problem with working out edges or anything like that.

Sorry, if this not what your are after.

If not look at the 2d graphics sections on line intersections, done with
simple equations.

Regards,

Mark Edgar.



Tue, 14 Aug 2001 03:00:00 GMT  
 diagramming problem
Thanks for your reply Mark.

I should have been more clear.

The line needs to be its own object.  The user will be allowed to select
points on the line and bend the line at those points.  For example the user
will be able to take a diagonal line that I generate when the connect the
two objects and make it into an L-shaped line.

Simon.

Quote:

>Why don't you use free hidden line removal.

>1. Draw line from box A centre to Box B centre.
>2. Draw boxes. ( with non transparent white inside )

>No problem with working out edges or anything like that.

>Sorry, if this not what your are after.

>If not look at the 2d graphics sections on line intersections, done with
>simple equations.

>Regards,

>Mark Edgar.



Tue, 14 Aug 2001 03:00:00 GMT  
 diagramming problem


Quote:
> I am wondering if anyone can help me.

> I am writing a program that models business processes.  It has an interface
> similar to Rational Rose (Visual Modeler).  I would like to be able to draw
> a connection between two objects.

[ ... ]

Quote:
> The connection should be from the edge of A to the edge of B using the edges
> of the objects closest to each other.  All this is based on a straight line
> from the center of A to the center of B.  Drawing a line from the center of
> A to the Center of B is no problem.  The problem arises from drawing the
> line only to the EDGE of each object.

The suggestion you've already gotten, to draw the lines, then draw the
boxes over them is probably the simplest one, though it'll cause a
little bit of flicker as the box is drawn over the line.

I'd try that out first to find whether it's really bothersome -- my
guess is that it won't be a problem.  If you decide it really is a
problem, you can do one of two basic things: you can set a clipping
region while you draw the line, so it won't be drawn except in the
proper area, or you can explicitly figure out the proper end-points
and only draw the line where you really want to.

Hopefully it'll only take a quick refresher in the geometry involved
to get you on the right track -- if you haven't taken a course in
geometry, you may find this hard to follow, but it's a bit much to try
to cover from the very beginning..

The usual formula for a line is y=mx+b.  m is the slope and b is the y
intercept.  Given a pair of points x1,y1 and x2,y2 (the centers of the
two squares in your case) you can find the slope between them as:
m=(y1-y2)/(x1-x2).  Now we have to find b -- this is the value of y
for an x value of 0.  Start by assuming that b=0, and figure out a
tentative value of y for x1: y0=m*x1.  Now, the difference between y1
and y0 is the y intercept of the line: b = y1-(m*x1)

You don't need to worry much about the slopes for the lines in the
boxes: for horizontal lines it's 0 and for vertical lines it's
infinite.  Likewise, a vertical line won't have a y intercept at all,
and a horizontal line will have a y intercept equal to its y value.

This makes life a bit easier to deal with: to find the intersection
between the sloped line and a horizontal line, you only have to figure
out the proper x value -- the y value is always the y value of the
horizontal line.

Likewise, for a vertical line you only have to figure out the y value.  
We'll start with this case.  Given a sloped line y=mx+b, we just
figure out the y value for the same x value as the vertical line.

Now there's one minor detail left: figuring out whether your sloped
line will intersect the horizontal or vertical boundary of the box.  
There are a number of ways to do this, but the simplest is probably to
figure out the slope from the center of the box to each corner of the
box.  The connecting line will normally have a slope between the
slopes of two of those lines, and it intersects the line connecting
the two corresponding corners.  If it happens to be exactly the same
slope as one of those lines, it means the line will run exactly
through the corner, and you already know its exact end-point
coordinate (the coordinate of that corner).  Note that as long as you
use a particular shape of box, you can pre-figure the slopes of these
four lines rather than re-figuring them every time you need to draw a
connecting line.



Tue, 14 Aug 2001 03:00:00 GMT  
 diagramming problem
Thank you very much Jerry, your information has been very helpful!!!

Simon.

Quote:



>> I am wondering if anyone can help me.

>> I am writing a program that models business processes.  It has an
interface
>> similar to Rational Rose (Visual Modeler).  I would like to be able to
draw
>> a connection between two objects.

>[ ... ]

>> The connection should be from the edge of A to the edge of B using the
edges
>> of the objects closest to each other.  All this is based on a straight
line
>> from the center of A to the center of B.  Drawing a line from the center
of
>> A to the Center of B is no problem.  The problem arises from drawing the
>> line only to the EDGE of each object.

>The suggestion you've already gotten, to draw the lines, then draw the
>boxes over them is probably the simplest one, though it'll cause a
>little bit of flicker as the box is drawn over the line.

>I'd try that out first to find whether it's really bothersome -- my
>guess is that it won't be a problem.  If you decide it really is a
>problem, you can do one of two basic things: you can set a clipping
>region while you draw the line, so it won't be drawn except in the
>proper area, or you can explicitly figure out the proper end-points
>and only draw the line where you really want to.

>Hopefully it'll only take a quick refresher in the geometry involved
>to get you on the right track -- if you haven't taken a course in
>geometry, you may find this hard to follow, but it's a bit much to try
>to cover from the very beginning..

>The usual formula for a line is y=mx+b.  m is the slope and b is the y
>intercept.  Given a pair of points x1,y1 and x2,y2 (the centers of the
>two squares in your case) you can find the slope between them as:
>m=(y1-y2)/(x1-x2).  Now we have to find b -- this is the value of y
>for an x value of 0.  Start by assuming that b=0, and figure out a
>tentative value of y for x1: y0=m*x1.  Now, the difference between y1
>and y0 is the y intercept of the line: b = y1-(m*x1)

>You don't need to worry much about the slopes for the lines in the
>boxes: for horizontal lines it's 0 and for vertical lines it's
>infinite.  Likewise, a vertical line won't have a y intercept at all,
>and a horizontal line will have a y intercept equal to its y value.

>This makes life a bit easier to deal with: to find the intersection
>between the sloped line and a horizontal line, you only have to figure
>out the proper x value -- the y value is always the y value of the
>horizontal line.

>Likewise, for a vertical line you only have to figure out the y value.
>We'll start with this case.  Given a sloped line y=mx+b, we just
>figure out the y value for the same x value as the vertical line.

>Now there's one minor detail left: figuring out whether your sloped
>line will intersect the horizontal or vertical boundary of the box.
>There are a number of ways to do this, but the simplest is probably to
>figure out the slope from the center of the box to each corner of the
>box.  The connecting line will normally have a slope between the
>slopes of two of those lines, and it intersects the line connecting
>the two corresponding corners.  If it happens to be exactly the same
>slope as one of those lines, it means the line will run exactly
>through the corner, and you already know its exact end-point
>coordinate (the coordinate of that corner).  Note that as long as you
>use a particular shape of box, you can pre-figure the slopes of these
>four lines rather than re-figuring them every time you need to draw a
>connecting line.



Thu, 16 Aug 2001 03:00:00 GMT  
 diagramming problem

     Hello,
     I think you will have to get down to the pixel level to do this.
     Sometime ago I wrote a small demo code for a class I was the
     teaching assistant for, and my algorithm(for doing something similar)
     was as follows(Note that I used ellipses):
     In the ****View::OnDraw(.....) function, you could use something like
     the following:
     pDC->Ellipse(pDoc->uleftx, pDoc->ulefty, pDoc->lleftx, pDoc->llefty);
     Note that ulefx,..... are the coordinates of the upper leftmost point
     (in terms of pixel values) etc, of the bounding rectangle of the
     ellipse. I am sure that there is a similar MFC function to draw a
     rectangle. Note that all of the actual pixel position calculations
     were done inside the ****Doc.cpp class. Then you could the other
     rectangles. Now as you know the pixel values themselves, you could
     use MoveTo(...) and LineTo(...) functions to draw the lines midpoints
     of the sides. Hope that helps.



Sat, 18 Aug 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Problem with ~40 table DB diagrams and Oracle

2. Auto C code generator beta, from visual diagrams

3. Diagram of LinkList pointers

4. source diagram

5. automatic flux diagrams

6. C language Syntax diagrams?

7. Programming using Nassi-Schneiderman diagrams

8. Auto 100% C code gen from visual diagrams -- upgrade

9. Wanted : C Syntax Diagram

10. expression for state transition diagram as C languages

11. Free source code diagramming software offerred

12. ANNOUNCE: Amazing tools for nice Nassi-Schneidermann Diagrams

 

 
Powered by phpBB® Forum Software