Joining lines & saving co-ordinates!

Well, I did manage to do something with my problem (posted last night) but here's another question.
I'll start again for those new to this...
I'm writing a 'sketch pad' program where the user draws 3 seperate lines (not touching) and then I have to extend them to make a decent looking triangle! Well, for now I've managed to get a canvas up and allow the user to draw lines.
Anyone got any ideas/tips on how to join the lines up, or just to save the co-ordinates (startx, starty, endx & endy) of each line in an array (so that I can repaint the canvas when it is put behind another window!)?
Here's the code I've done so far;
Sketcher.java
import java.awt.*;
import java.awt.event.*;
public class Sketcher extends Frame {
     private Canvas canvas;
     public Sketcher() {
          setSize(500, 500);
          setTitle("Sketch Pad");
          canvas = new Canvas();
          add(canvas, "Center");
    public static void main(String[] args) {
          Sketcher f = new Sketcher();
          MouseWatcher mw = new MouseWatcher();
          f.canvas.addMouseListener(mw);
          f.canvas.addMouseMotionListener(mw);
          f.show();
MouseWatcher.java
import java.awt.*;
import java.awt.event.*;
public class MouseWatcher extends MouseAdapter implements MouseMotionListener {
     private Point p, oldp;
     public void mousePressed(MouseEvent e) {
          oldp = e.getPoint();
     public void mouseReleased(MouseEvent e) {
          p = e.getPoint();
          Graphics g = ((Canvas)e.getSource()).getGraphics();
          g.drawLine(oldp.x, oldp.y, p.x, p.y);
          oldp = p;
          g.dispose();
     public void mouseDragged(MouseEvent e) {
     public void mouseMoved(MouseEvent e) {
}Any help greatly appreciated... duke dollars available too, heh!

Was bored......
Havnt tried this but see if it works
  private Point p, oldp;
  private Point[] pts = new Point[6];
  int ctr = 0;
  int x1[] = new int[3];
  int y1[] = new int[3];
  int x2[] = new int[3];
  int y2[] = new int[3];
  public void mousePressed(MouseEvent e) {
    oldp = e.getPoint();
    x1[ctr] = (int)oldp.getX();
    y1[ctr] = (int)oldp.getY();
  public void mouseReleased(MouseEvent e) {
    p = e.getPoint();
    Graphics g = ( (Canvas) e.getSource()).getGraphics();
    g.drawLine(oldp.x, oldp.y, p.x, p.y);
    x2[ctr] = (int)oldp.getX();
    y2[ctr] = (int)oldp.getY();
    ctr++;
    oldp = p;
    if (ctr == 3) {
      drawTriangle(e);
    g.dispose();
  private void drawTriangle(MouseEvent e) {
    Graphics g = ( (Canvas) e.getSource()).getGraphics();
    Canvas c = (Canvas) e.getSource();
    g.setColor(Color.white);
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
    g.setColor(Color.black);
    Point[] pointi = new Point[x1.length];
    for(int z1=0; z1<x1.length; z1++) {
      // Work out b
      int b1 = (y2[z1]-y1[z1]) / (x2[z1]-x1[z1]);
      // work out a
      int a1 = y1[z1] - (b1 * x1[z1]);
      // now the other point
      int z2 = z1 + 1;
      if (z2 >= x1.length) z2=0;
      int b2 = (y2[z2]-y1[z2]) / (x2[z2]-x1[z2]);
      // work out a
      int a2 = y1[z2] - (b1 * x1[z2]);
      // Get the intersection
      int xi = (a1-a2) / (b2-b1);
      int yi = a1 + (b1*xi);
      // store this point
      pointi[z1] = new Point(xi, yi);
    for(int i1=0; i1<pointi.length; i1++) {
      int i2 = i1 + 1;
      if (i2 >= pointi.length) i2 = 0;
      g.drawLine(pointi[i1].getX(),
                 pointi[i1].getY(),
                 pointi[i2].getX(),
                 pointi[i2].getY());
    ctr = 0;
  }Rob.

Similar Messages

  • IF Statement in Join Line

    Is it possible to use a IF statement (i.e. CASE, DECODE) in the Join Line?
    I need create a query that depending on the value of a column it will determine if I use a column A or column B in my join statement. I was thinking something like the following:
    Select a.Value1, a.Value2, b.ColumnA, b.ColumnB
    FROM Table1 a
    INNER JOIN Table2 b ON a.Value2 = (if b.ColumnZ='Dept' then b.ColumnA else b.ColumnB END)
    Oracle Version 10g
    OS Windows XP
    Thanks in advance!

    Hi,
    Remember what a CASE expression does: it returns a single value in one of the SQL data types (such as VARCHAR2, NUMBER or DATE).
    Each THEN (or ELSE) clause of a CASE expression references something that the CASE expression might return, so after each THEN (or ELSE) keyword there must be a single value in one of the SQL data types.
    So you can't say:
    case tdsi.level_code
         when  'L'  then  tdsid.privilege_code = tdlm.location_code
         when  'R'  then  tdsid.privilege_code = tdlm.region_code
         when  'C'  then  tdsid.privilege_code = tdlm.country_code
    endWhat is the data type being returned? "tdsid.privilege_code = tdlm.location_code" is not a single value in any of the SQL data types.
    If location_code, region_code, country_code and privilege_code all have the same data type, then you can do something like this:
    join      dirpipe.dirpipe_location_map      tdlm      on      case tdsi.level_code
                                            when 'L' then tdlm.location_code
                                            when 'R' then tdlm.region_code
                                            when 'C' then tdlm.country_code
                                       end     = tdsid.privilege_code

  • Illustrator CS3 crashes if join lines on different layers

    Sent in a crash report earlier, but didn't realize the source of the error at the time -- which was that the two lines I was attempting to join were located in separate sublayers. Illustrator did not give me an error message when I attempted to join the lines, instead the lines I had joined simply vanished. If I then hit command Z to undo, the file would crash. This behavior was repeatable multiple times.
    I realize this is a bug in an older version of the software, but having this info in the forums may be of use for people still running CS3, and, if this bug has not yet been corrected in more recent versions of the software, then I hope the tech folks will take notice.

    Peter, Steve -
      That's interesting - and I was sure I'd isolated the source of the problem. I'm working in the mac OS (snow leopard) and CS3 suite is the Design Premium version. I had 3 sublayers in my layer, and each of those sublayers had about 20 paths in them. The behavior occurred repeatedly when I tried to join 2 lines that were in different sublayers (one of the endpoints was created by clipping a section out of an oval on one of the sublayers). I thought it was not a random behavior, b/c I reproduced it 4 or 5 times in a row, with 2 different pairs of lines. Yet I was able to join lines on any sublayer with no problem, and when I pulled all the lines out of the sublayers, I was able to join the two sets of lines that had previously been causing the crash without any difficulty. So I'm not sure why your tests did not reproduce the problem -- or why I had the problem in the first place.
    Thanks,
    Suzi

  • Joining line paths in CS5

    Hi,
    I am working on a line art project and trying to figure out how to join an endpoint on one path to another path. Here is pic of what I am trying to do:
    http://imageshack.us/photo/my-images/862/screenshot20111215at150.png/
    Is there a way to join a line to the middle of another line and keep the line styles? Right now some of my paths end abruptly in a square end, but how do I joint them together? I tried using the "join" command, but that requires 2 endpoints.

    Spinky,
    It seems that in this case you may give the chin/cheek paths white fills and extend the troublesome paths, keeping them underneath the others; if that is not too cheeky.

  • Joining Line Segments

    The line looks like it's connected, but it's not. When I apply the brush effect it becomes disjointed. I want it to be one smooth stroke. Is there any way to join the line segments without having to redraw the stroke? I ask this because the line was imported into Illustrator from Flash, there are many more and I don't want to have to redraw them all. Thanks in advance for any help.

    Bob,
    Hopefully, you can:
    1. Deselect the path and then drag across each set of Anchor Points where the brushes go thin;
    2. Object>Path>Join.
    If you select the lot before 1+2, and look in the Layers palette, or open Window>Document Info, and select Objects in the flyout menu, you should be able to see that there are multiple paths; the latter shows the number of points in each selected object.
    If 1 + 2 do (or should it be does) not work, there are probably multiple Anchor Points at the end(s) of either/both of the paths to be joined; the surplus should be deleted.
    Or the paths may be grouped, and should be ungrouped first; that may also be seen in the Layers palette/Document info.

  • Joining Line Segments in CS6

    I am drawing a simple diamond shape made with one rectanlge shape and multiple line segments.  As I drew the design, I made sure to connect all the segments at the anchors.  When I select all of the segments and try to join the paths, the end points or corners are not smooth.  In other words, some of the line segment ends hang over the edges...  What am I doing wrong?  Thanks!
    The image below shows the left side of the diamond, where the top portion meets the bottom...

    Thank you, DayForce.  Changing the corner type to "round join" did the trick!  May I ask another question?  When I select all the segments and join the paths, I get an additional line segment from one point to another.  How can I elminiate this?

  • Join Line Segments (road segments) SDO_AGGR_UNION/SDO_AGGR_CONCAT_LINES

    Hi,
    I have road segments I need to join/merge in order to get the complete road axe. Unfortunately I have some segements which are not joined and the resulting road axe has a gap.
    When I look at the road segements and the join result it seems to me that aggregation does not work for roads which either have segements which are disjoint (we have a few roads where single segments do not touch) or if a road has two or more "branches" (just take the letter "Y" as example for it).
    (1) SDO_AGGR_CONCAT_LINES
    Didn't work at all - I could not create a view using SDO_AGGR_CONCAT_LINES. As the documention mentions - not suitable if you have arcs (we have).
    (2) SDO_AGGR_UNION
    I tried SDO_AGGR_UNION as well although the documentation mentions - "Do not use SDO_AGGR_UNION to merge line string or multiline string geometries; instead, use the SDO_AGGR_CONCAT_LINES spatial aggregate function."
    (3) SDO_AGGR_SET_UNION
    I tried SDO_AGGR_SET_UNION as well. It sounded promising as the documentation doesn't mention anything related to arcs but says: "Can aggregate sets of lines..."
    2 and 3 give the same result. Please have a look at the screenshot (mh, looks like I can't upload a picture...)
    I would like to aggregate the segements - is there another function in Oracle I could use?
    Any idea, whether SDO_AGGR_UNION / SDO_AGGR_SET_UNION are / are not suitable for my dataset?
    Many thanks, Rob
    My view definitions:
    CREATE OR REPLACE FORCE VIEW AV_V_STRASSEN_2
    AS
      SELECT l.fid,
        ln.location_name,
        SDO_AGGR_UNION(sdo.SDOAGGRTYPE(rs.geom, 0.005)) geom
      FROM lm_lo_location l,
        lm_lo_location_name ln,
        lm_lo_road_section rs
      WHERE l.fid = ln.fid_lo_location
      AND l.fid   = rs.fid_lo_location
      GROUP BY l.fid,
        ln.location_name;
        CREATE OR REPLACE FORCE VIEW AV_V_STRASSEN_3
    AS
        SELECT l.fid,
        ln.location_name,
        sdo_aggr_set_union (get_geom_set ('lm_lo_road_section', 'geom','fid_lo_location = ', l.fid), .0005 ) geom
      FROM lm_lo_location l,
        lm_lo_location_name ln,
        lm_lo_road_section rs
      WHERE l.fid = ln.fid_lo_location
      AND l.fid   = rs.fid_lo_location
      GROUP BY l.fid,
        ln.location_name;

    R o b wrote:
    after some further tests I found out that the cause of the issue seems to be the application I used for viewing my road network.
    I displayed the view in SQLDeveloper and with FME and both look fine - result is expected (for view 2 and 3). But initially I used a different package for checking the view visually.
    Yes, that can happen sometimes. Currently I've been working with one of the biggest GIS-applications out there, and I have noticed that especially when zooming in or out rapidly gaps appear between lines (when I know for certain that there are no gaps - because I checked). It's weird that, but it can trick you into believing things are not right.
    R o b wrote:
    Stefan - thanks for yopur reply:
    - I need the roads not road segements when displaying the data in our GIS system, most users want a road not single segements
    - performance : will see, if it's not good I will create a mat. view, road network is quite static and doesn't change often
    - gaps : there are no gaps in our data set (but "gaps" appeared when I displayed the view in one specific software package).
    - sdo_aggr_union / sdo_aggr_set_union seem to do what I want and seem to work with our data as well
    Roads do make more sense to users - that is true. If you also need segments, maybe the LRS stuff can help you there: create the necessary segments on the fly when needed? On the other hand you are right, road networks tend to stay the same for a long time, and if the do change you usually have plenty of notification so an MV might be best (also depends on the number of users and the type of users I suppose).
    Glad it's working for you now!
    Cheers,
    Stefan

  • AutoCAD drawings INTO Illustrator / How can I join line segments?

    Good day;
    ~ using Illustrator 5
    ~ importing technical drawings from CAD (think, complex mining shafts / exploded drawings and the like...)
    ~ want to manipulate imagery in Illustrator
    ~ all drawings are importing as individual lines / shape....a simple rectangle is four separate lines
    ~ is there an efficient way to "OPEN' or to "IMPORT" these complex drawings and have the CAD lines unite as closed shapes?!
    ~ isolating each shape / selecting nodes / 'joining' / is just NOT the best way to kill my day
    ~ willing to download solid recommended plug-ins
    S.O.S.!!
    Thank you in advance,
    Laura

    Laura,
    Here is a thread for FrameMaker users that has some data you might find useful in doing what you want: http://forums.adobe.com/thread/316489
    I have to handle this headache on occasion with MicroStation DGN files and I don't know of any plug-ins that will do this for either DWG or DGN. I try to get an EPS export from the CAD program first, if that export option is available, and bring it into Adobe Illustrator. This should be a standard for any CAD software. The next thing I try is PDF export and bring that into AI. If that doesn't work...
    Your next problem is that version 5 of Illustrator is 17 years old! I'm sorry to inform you but that could be the problem you face, your software and computer are too old and that version of Illustrator isn't sophisticated enough to handle what you want to handle. You may have no option but to get a newer Mac or Windows computer and get a newer version of AI, at least!
    I run Windows XP on a Dell Dimension 5150 and AI CS4 at work and I can barely get by at home with a 4 year old Mac Mini running Mac OS X 10.5 and AI CS2. That should give you a baseline to work from.
    I hope this last hasn't upset you too much.

  • How to join line within ellipse

    I have the following shape:
    Which is an ellipse which I happened to draw a line inside of. My goal is to be able to join the line with the ellipse so I can make it part of the shape, then I'd like to chop off the top of the ellipse (the part on top of the line).
    Any help would be appreciated.
    Thanks.

    Kiss,
    If I understand it in the right way, you can just extend the line past the the boundary of the ellipse, than Object>Path>Divide Onjects Below, then delete the cap.
    You can etxend the line by adding something to the W value (or multiply it by something) in the Transform palette/panel.

  • Join line to define object

    Hi,
    i'm trying to create a rope under Illustrator CS5.
    for that i created the usual "S" line and multiply it in order to create the rope effect.
    now i would like to join 2 "S" line together to create a new shape in which i can fill with a color. In that way i will be able to create an alternated colored rope.
    however i have some problem to join 2 "S" line in order to create the shape to fill.
    Do you have an idea on the best method to do that ?
    thx.

    what Jetalmage wrote set the filling color at the beginning and you can't change it later on...you have to recreate a new rope from the coloring step...
    Can't understand what you're saying here. For clarity: When you create a Brush, the dialog provides a Colorization option. Using that feature allows you to change the color of a Brush Effect at the object level any time you want. So you can use one Brush to create ropes (wires, whatever) of any color. For example, note that the artwork of the Brushes shown below are all built in grayscale. The color of the individual wire insulations is applied at the object level, as you would for any ordinary stroke. Thus, the two Brushes that are applied to path 4 can be used to make a wire of any maincolor/tracecolor combination. The colorization options are described in online Help, and are even illustrated in the Brush Options dialog itself.
    So no, you do not have to create a separate Brush for each color rope (if that's what you are saying).
    Regarding joining paths: Join now works without having to "direct select" endpoints with the white pointer. You can just select the paths you want to join, and the Join command will join them at their nearest endpoints. You can override this by selecting the endpoints you want to join when they are not the nearest pair.
    JET

  • Draw non-joined lines from endpoint of existing lines

    I asked on the general AI forum how to draw lines from existing line endpoints without the two being joined, and I got the answer that you can't. So I think this calls for a feature request: give the user the possibility to draw a line at the endpoint of a pre-existing line without joining the two. Up till now the current functionality has two drawbacks for me:
    1. It makes creating the following pulse diagram a PITA:
    When I draw a line starting from the arrowhead the arrowhead moves to the new endpoint. Here I had to draw the new line elsewhere on my page and drag it over the arrow.
    2. If you draw a line to the end of an existing line in a group it gets automatically joined to it, and thus becomes part of that group, even when you're not working in isolation mode. Again I have to draw my line at another place on the page and drag it to the grouped object afterwards.
    So, feature request: allow lines sharing a common end- and start point without being joined.

    This is not the ability of usual flex classes. You should explore on how the 3D coordinates system of Flex works, and learn some classes usability, such as Matrix3D, for example.

  • How to join lines

    I've just started using illustrator to design a few templates. I'm struggling with the lines, typically where I've deleted a portion of line I find that the two adjacent lines don't fully connect. how do I rectify it? see picture.

    mdk,
    The end points seem to at least almost coincide. If not, averaging may change the adjacent segments visibly.
    Normally, you may find and correct a lack of coinciding by using the Direct Selection Tool together with the Smart Guides (with the right settings). You may:
    1) Click each of the path segments adjacent to the end point and then follow the path with the mouse hovering all the way;
    If the end Anchor Points coincide, Smart Guides will say path until you reach the end, then anchor, for the topmost path, and they will end saying intersect for the bottommost path.
    If they say anchor for both (maybe after saying intersect first for the bottommost path) you have a mismatch;
    If you have a mismatch, you may:
    2) ShiftClickDrag the end Anchor Point(s) in question to coincide with the other path/Anchor Point.

  • How to make cursor lines appear in saved file

    I have a graph that has 3 cursor lines.  They are visible on the graph.
    When saving the graph to a file (.png or .jpg) the graph waveform is visible, but the cursor lines are not.
    The image data does not contain the cursor lines.  How do I include those to the image data.
    I verified the image data using an image indicator and the appropriate VI..  So for some reason, the image that is being saved is of the indicator (Waveform Graph) and the waveform (data), but not the cursor lines. 
    I'm sure I've saved images of a graph that included the cursor lines in the past (LV7.x), but I cannot remember what I did. 
    Thanks,
    RayR

    Thanks Christian,
    I (may) have found the problem...  At one point, I clear all cursor lines.  I may have a race condition between clearing the lines & saving image to file.
    I did see the cursor lines in one instances when I stopped the program prematurely. 
    I knew it had to be siomple.  I didn;'t recall doing something special the last time I did this..
    Thanks!
    RayR

  • Drawing line from existing one without joining

    How can I draw a line from the endpoint of an existing line (snap to grid is on), without the lines being joined?  Joining causes two problems for me:
    1. The arrowhead at the end of the existing line moves to the end of the joined line, whereas I want the arrowhead in the middle of the combined line.
    2. Even without entering isolation mode the new line gets joined to a line which belong to a group, thus becoming part of that group as well. This defies the use of grouping to create logically connected units.
    TIA
    Steven

    JETalmage wrote:
     ...Worst-of-class Bezier drawing interface. The Pen Tool has absolutely no business affecting pre-existing unselected paths by default. The Pen Tool is not a selection tool, and it violates the entire meaning of something's being selected.
    JET
    while I agree in principle, on practice when clicking on end points with the pen tool most of the time I do want the paths to join but a lot of other times I do not. So, the best practical solution at least for me would be just holding the Spacebar when clicking on an end point to prevent joining without the need to click away and then drag in place. And they should make this an option in the Preferences for those who want to hold Spacebar only when joining.
    The bigger problem is that with overlapping points and edges, Illustrator uses the stacking order and not the selected object when auto joining or adding points which is actually not practical in any case. For example if there are several lines starting at the same point, not the selected but the topmost line will be joined and with overlapping edges adding a point is impossible if the selected edge is not on the top.

  • Line saver tariffs - take a second look at the fig...

    Having done the maths on BT's "line saver upfront paying of rental", the deal is not quite what is portrayed, at least not for me.  ! currently pay a line rental of £13.29 pm, but get a paper-free discount of £1.25 pm, effectively reducing the line rental to £12.04 pm  ( or £144.48 per year).  If I change to "line-rental", the monthly fee works out at £9.99 pm (or £119.88 per year).  However, on changing to "line-rental saver", I would loose the paper free discount of £1.25 pm, resulting in an effective rate of £11.24 pm.  The bottom line saving being only 80p per month (or £09.60 per year, and not the advertised annual saving of £39.60 per year).  Hardly an incentive to pay upfront to BT !!  P.S. the figures are also pro-rata when the vat increases 20 % in Jan 2011.

    Your logic and maths is flawed.
    Without Line Saver Rental, the total monthly charge for line rental is £13.29 less the paperless billing discount of £1.25, making £12.04 as you correctly state.
    With Line Rental Saver, the monthly charge is one twelfth of £119.88 which is £9.99, meaning that you are saving £2.05 per month or £24.60 per year.
    Your logic is flawed in double accounting the paperless billing discount.
    What is advertised is correct for new customers who cannot get the paperless billing discount as it has been generally removed for new customers.
    Their saving is hence £24.60 plus twelve times £1.25 which equals £39.60 for new customers.

Maybe you are looking for