[CS4/JS]: Draw three touching circles

This little javascript just might be useful; perhaps not for everyone, though 
Select a triangle (either closed or open, doesn't matter; as long as it has exactly 3 anchor points) and run this script. It'll draw three thin-lined circles with their centers on the triangle points, and their radii adjusted so all three of them touch each other.
Copy, paste into a plain text editor -- Adobe's own ESTK Editor is good -- and save into Illustrator's Scripts folder, or anywhere else (but then you'd have to browse for it every time you want to run it). Save as "draw3circles.jsx" -- when saved in Illy's Scripts folder, it'll be visible next time you restart Illustrator.
Select a triangle, run the script. If you don't have a valid selection, it'll do nothing at all.
//DESCRIPTION:Draw Three Touching Circles on a Triangle
// A Jongware Script, 30-Sep-2010
if (app.documents.length > 0 && app.selection.length == 1 && app.selection[0].hasOwnProperty("pathPoints") && app.selection[0].pathPoints.length == 3)
     p1 = new point (app.selection[0].pathPoints[0].anchor);
     p2 = new point (app.selection[0].pathPoints[1].anchor);
     p3 = new point (app.selection[0].pathPoints[2].anchor);
     dc = p1.distance(p2);
     da = p2.distance(p3);
     db = p3.distance(p1);
     ra = da - (da + db + dc)/2;
     rb = db - (da + db + dc)/2;
     rc = dc - (da + db + dc)/2;
     black = new GrayColor(); black.gray = 100;
     if (ra)
          e = app.activeDocument.pathItems.ellipse (p1.y+ra,p1.x-ra,2*ra,2*ra); e.strokeWidth = 0.1; e.strokeColor = black; e.fillColor = NoColor;
     if (rb)
          e = app.activeDocument.pathItems.ellipse (p2.y+rb,p2.x-rb,2*rb,2*rb); e.strokeWidth = 0.1; e.strokeColor = black; e.fillColor = NoColor;
     if (rc)
          e = app.activeDocument.pathItems.ellipse (p3.y+rc,p3.x-rc,2*rc,2*rc); e.strokeWidth = 0.1; e.strokeColor = black; e.fillColor = NoColor;
function point (arr)
     this.x = arr[0];
     this.y = arr[1];
     this.distance = function (pt) { return Math.sqrt ( (this.x-pt.x)*(this.x-pt.x) + (this.y-pt.y)*(this.y-pt.y) ) };

I don't know yet what I might use it for, but it's fun! Give me a couple of hours...
Thanks,
Peter

Similar Messages

  • Possible screen hardware fault - three perfect circles look like suction cup marks

    I have an iMac 27-inch, mid 2011. I purchased the machine in October 2011.
    I have always looked after my screen by protecting it from dust with a light cover but suddenly today I notice three perfect circles - like suction cup outlines. Two of them are identical in size 5cm across sitting side by side. The other one is in the left bottom quadrant and is about 3cm across - looks like there may have been writing across the top arc but is too small to make out.
    I am assuming these marks are from the manufacturing/assembly process when the glass was suction-cupped to put onto the machine. Why have they become visible suddenly now nearly 4 years later?
    I tried to clean them off with a isopropyl alcohol free wipe but nothing comes off. The circles are also casting a shadow onto the screen contents. There doesn't appear to be any raised surface to these marks.  They don't budge. But now I have like a white cloud of where I tried to clean them off when the screen was on and hot. I'm hoping this doesn't last.
    What can I do?

    Additional note to my above query...
    The screen has a large amount of what looks to be condensation - that appears like a big milky cloud - this slowly shrunk and then disappeared after shutting down.
    How is there condensation in the centre where the circular suction cup marks have suddenly appeared? Is my screen laminate separating or something?

  • HT6114 somehow I have lost the three little circles at the top left of my screen: red to x out, yellow to minimize and green to maximize.  How do I get them back?

    I have lost the three little circles on the upper left of my screen:  red to exit, yellow to minimize and green to enlarge.  How can I get them back?

    sounds like you are in full screen mode for that app. you will not see the red yellow grn.
    exit full screen Upper right corner, click the double arrows
    or in the drop down menu>View exit full screen

  • Drawing elements in circles

    Hi friends,
    I am trying to draw elements in incremental circles starting with a small circle, meaning incrementing the no of elements in the next outer circle. The problem is that before properly filling a circle, my program is drawing another outer circle and putting elements in it. So, the circles seems to be broken.
    The description seems to be confusing. Please have look at the code.
    import java.awt.Color;
    import java.awt.EventQueue;
    import java.awt.Graphics;
    import java.util.ArrayList;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class CircularDrawingNew extends JPanel
         public static void createUI()
              JFrame f = new JFrame("Circular Drawing New");
              f.add(new CircularDrawingNew());
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.setSize(1100, 900);
              f.setLocationRelativeTo(null);
              f.setVisible(true);
         public static void main(String[] a)
              EventQueue.invokeLater(new Runnable() {
                   @Override
                   public void run()
                        CircularDrawingNew.createUI();
         @Override
         public void paintComponent(Graphics g)
              super.paintComponent(g);
              int totalElements = 0;
              int elementsPerRing = 9;
              int location = 500;
              double verticalGap = 10.0;
              double radius = 40.0;
              System.out.println("==================================== START ==============================");
              int count = 0;
              int circleCount = 0;
              ArrayList<Color> colors = new ArrayList<Color>();
              colors.add(Color.GREEN);
              colors.add(Color.YELLOW);
              colors.add(Color.RED);
              int k = 1;
              int space = 80;
              limit:
              for (; ;)
                   double circumference = 2 * 3.14 * radius;
                   System.out.println("Circumference : " + circumference + " element count is : " + elementsPerRing + " cc is : " + circleCount + " space is : " + space);
                   for (int j = 0; j < elementsPerRing; j++)
                        if (totalElements > 750)
                             break limit;
                        if (count == 3)
                             count = 0;
                        g.setColor(colors.get(count));
                        double x = location + radius * Math.cos(Math.toRadians(verticalGap));
                        double y = location + radius * Math.sin(Math.toRadians(verticalGap));
                        g.fillOval((int) x, (int) y, 10, 10);
                        g.setColor(Color.black);
                        g.drawString(String.valueOf(k), (int) x, (int) y);
                        verticalGap += 360 / elementsPerRing;
                        k++;
                   count++;
                   circleCount++;
                   radius += 30;
                   double d = (circumference / space);
                   elementsPerRing += (int)d;
                   totalElements += elementsPerRing;
                   if(circleCount >= 6 && circleCount <= 8)
                        space = space + 20;
                   else if(circleCount >= 8 && circleCount <= 10)
                        space = space + 40;
                   else if(circleCount > 10)
                        space = space + 60;
                   else
                        space = space + 10;
              System.out.println("==================================== DONE ==============================");
    }

    Your entire problem is rounding errors and truncation. Your algorithm was correct, but you ineffectively mixed int and double types of numbers together and relied on autoboxing to do the right thing for you---DON'T DO THAT! When you mix a double with an int, you are going to do int math and then it will be converted to an int if that is what it takes as the destination variable. You have several places in your code where you just take any number and do some math with any other number and you where caught by it this time. Learn how number systems interact and errors that are inherent in each number system.
    Here is your type corrected code (now working as you desire--without any significant modifications other than number type corrections):
    import java.awt.Color;
    import java.awt.EventQueue;
    import java.awt.Graphics;
    import java.util.ArrayList;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class ForumJunk extends JPanel{
      public static void createUI(){
        JFrame f = new JFrame("Circular Drawing New");
        f.add(new ForumJunk());
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(1100, 900);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
      public static void main(String[] a){
        EventQueue.invokeLater(new Runnable(){
        public void run(){
          ForumJunk.createUI();
      public void paintComponent(Graphics g){
        super.paintComponent(g);
        int totalElements = 0;
        int elementsPerRing = 9;
        int location = 440;
        double verticalGap = 10.0;
        double radius = 40.0;
        System.out.println("==================================== START ==============================");
        int count = 0;
        int circleCount = 0;
        ArrayList<Color> colors = new ArrayList<Color>();
        colors.add(Color.GREEN);
        colors.add(Color.YELLOW);
        colors.add(Color.RED);
        int k = 1;
        double space = 80.0;
        limit:
        while(true){
          double circumference = 2.0 * Math.PI * radius;
          System.out.println("Circumference : " + circumference + " element count is : " + elementsPerRing + " cc is : " + circleCount + " space is : " + space);
          for(int j = 0; j < elementsPerRing; j++){
            if(totalElements > 750) break limit;
            if (count == 3) count = 0;
         g.setColor(colors.get(count));
         double x = location + radius * Math.cos(Math.toRadians(verticalGap));
         double y = location + radius * Math.sin(Math.toRadians(verticalGap));
            g.fillOval((int) x, (int) y, 10, 10);
            g.setColor(Color.black);
            g.drawString(String.valueOf(k), (int) x, (int) y);
            verticalGap += 360 / (double)elementsPerRing;
            k++;
          count++;
          circleCount++;
          radius += 30.0;
          double d = (circumference / space);
          elementsPerRing += (int)d;
          totalElements += elementsPerRing;
          if(circleCount >= 6 && circleCount <= 8) space = space + 20;
          else if(circleCount >= 8 && circleCount <= 10) space = space + 40;
          else if(circleCount > 10) space = space + 60;
          else space = space + 10;
        System.out.println("==================================== DONE ==============================");
    }BTW: you may notice that I changed the name--I do that with any project I load off of the forums--and I also change your whitespace formatting to allow me to see more of your code on the screen.
    Oh, I did change your empty for loop to a while(true)--just my preference again--and I changed you location from 500 to 440 to cernter better in the display.

  • How to draw a perfect circle and how to make sure it is perfectly centered inside a square

    How to draw a perfect circle and how to make sure it is perfectly centered inside a square in Photoshop elements using the Ellipse option.

    1. Create a square canvas.
    2. With the Elipse tool, hold down Shift (Shift forces a circle). Draw the circle anywhere on the canvas (Shape 1 in this example).
    3. Simplify the circle layer
    4. Ctrl-click the layer to select the circle.
    5. Copy the selection to the clipboard (Edit > Copy).
    6. Deselect the selection.
    7. Paste from the clipboard (Edit > Paste). The pasted circle (Layer 1) will be centered.
    8. Delete the original circle layer.
    NOTE: Step 6 is the key. This guarantees that the pasted circle will be centered.
    If you want a circle completely within a square you can simply draw and simplify a circle on any shape canvas. Ctlrl-click the circle to to select it and copy to the clipboard.
    Then do File > New from Clipboard. This creates the circle cropped to a square on transparent background.

  • Drawing and Filling Circle and Polygon.

    I have searched about creating these but cannot understand properly. 
    Let SetPixel(X,Y) be the function to set the pixel. I am working in unity3d for drawing on texture.
    Allow time to reverse.

    besides what Armin said
    which setpixel function do you mean ?
    the bitmap.setpixel or the Win32 setpixel ?
    also why would you want it in vb when you don't plan to use vb ?
    I am writing class library for unity3d in vb.net.
    "SetPixel(x,y)" is just a procedure that sets pixel on (x,y). It is enough for drawing.
    I am not dealing with color or anything. Just need to set pixels at right position.
    I tried and found this: (It is to draw non-filled circle)
    Public Function Apply(Texture As Texture2D) As Texture2D Implements Image.Appliments.Apply
    Dim x0 As Integer = Me.X
    Dim y0 As Integer = Me.Y
    Dim x As Integer = Radius
    Dim y As Integer = 20
    Dim RadiusError As Integer = 1 - x
    While x >= y
    Texture.SetPixel(x + x0, y + y0, Color)
    Texture.SetPixel(y + x0, x + y0, Color)
    Texture.SetPixel(-x + x0, y + y0, Color)
    Texture.SetPixel(-y + x0, x + y0, Color)
    Texture.SetPixel(-x + x0, -y + y0, Color)
    Texture.SetPixel(-y + x0, -x + y0, Color)
    Texture.SetPixel(x + x0, -y + y0, Color)
    Texture.SetPixel(y + x0, -x + y0, Color)
    y = y + 1
    If RadiusError < 0 Then
    RadiusError = RadiusError + 2 * y + 1
    Else
    x = x - 1
    RadiusError = RadiusError + 2 * (y - x) + 1
    End If
    End While
    Texture.Apply()
    Return Texture
    End Function
    Allow time to reverse.

  • Assistive Touch Circle covers the 2X Circle

    Assistive touch will allow my disabled grandson to go home (he doesn't have the strength to use the home button). However, when enabled, the assistive touch circle covers the circle that allows him to enlarge the iPhone apps to full screen on the iPad. He really needs BOTH circles available. Any suggestions?

    Thank you! My grandson is feeling much more independent now that he need not ask for help everytime he wants to "go home."
    Thanks to you for helping me figure this out and thanks to Apple for caring.
    Nana Barb

  • Photoshop CS4 Brush Draws Circles

    Hi. This wasn't happening but now, all of my brushes draws circles like that. Is it supposed to happen? If answer is no, how can I solve it? Thanks.

    Today I've installed the latest Forceware Drivers 180.60 from http://www.laptopvideo2go.com/ to test the bug behaviour.
    The brush cursor now seems to be able to handle big brush sizes but the performance is reduced noticable.When painting inside a new document the rendering of the brush path is done after painting over the area, even when using small brush sizes.
    So let's wait until Nvidia/Lenovo roll out a new driver.
    Message Edited by mikey on 11-24-2008 07:57 AM

  • Photoshop CS4 OPENGL Drawing problem with Photoshop CS4

    Hello, I've had this problem since i installed photoshop cs4, and its finally getting on my nerves and i'm looking for a fix.
    I am on Windows XP SP3, NVIDIA 8800GTS. The OPENGL Drawing in Photoshop CS4 works fine, but a lot of times, when i start photoshop, it'll say that OPENGL Drawing is disabled and i'll have to go in to preferences and re-endabe and restart photoshop again to get it working. Please help, it's really annoying

    NVIDIA apparently does not update their drivers specifically to correct Photoshop CS4 incompatibilities. There release notes have never mentioned bugs or fixes relating to Photoshop.
    Try setting the 3D settings to Performance (rather than Quality) in the NVIDIA Control Panel.

  • Last question for today - how to draw with API circle of N pixels radius

    Hi,
    While I'm bit of exhausted while fighting with those paths movement (see my other thread in this forum) - I'd like to ask maybe someone has code snippet, which shows how to draw a circle of N pixels/N mm/inches radius?
    There is one helper function for that inside SDK samples:
    PDEPath DrawCurve(ASFixed x, ASFixed y, ASFixed x1, ASFixed y1, ASFixed x2, ASFixed y2, ASFixed x3, ASFixed y3, int lineWidth, int r, int g, int b)
    but I'm just out of my mind for today what parameters should be provided and how many calls of it I should write.
    Any help would be appreciated.

    You call it four times...
    Here is a snippet that explains the math...
    /* 4/3 * (1-cos 45)/sin 45 = 4/3 * sqrt(2) - 1 */
    #define ARC_MAGIC ((ASFixed) 0.552284749)
    #define PI ((ASFixed)3.141592654)
    void DrawCircle( ASFixed inCenterX, ASFixed inCenterY, ASFixed inRadius )
    /* draw four Bezier curves to approximate a circle */
    MoveTo( inCenterX + inRadius, inCenterY );
    CurveTo( inCenterX + inRadius, inCenterY + inRadius*ARC_MAGIC,
    inCenterX + inRadius*ARC_MAGIC, inCenterY + inRadius,
    inCenterX, inCenterY + inRadius );
    CurveTo( inCenterX - inRadius*ARC_MAGIC, inCenterY + inRadius,
    inCenterX - inRadius, inCenterY + inRadius*ARC_MAGIC,
    inCenterX - inRadius, inCenterY );
    CurveTo( inCenterX - inRadius, inCenterY - inRadius*ARC_MAGIC,
    inCenterX - inRadius*ARC_MAGIC, inCenterY - inRadius,
    inCenterX, inCenterY - inRadius );
    CurveTo( inCenterX + inRadius*ARC_MAGIC, inCenterY - inRadius,
    inCenterX + inRadius, inCenterY - inRadius*ARC_MAGIC,
    inCenterX + inRadius, inCenterY );
    Close();

  • How to draw a 2d circle or 3d ball using opengl es

    hello i am not able to draw a ball using opengles and finding its center.
    and i have to move this ball using touch event or acclerometer. any suggestions please help

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.BLACK);
        int centerX = 200;
        int centerY = 200;
        int numPoints = 10;
        double radius = 100;
        double angleIncrement = Math.PI * 2 / numPoints;
        double tempAngle = 0.0;
        for (int i = 0; i < numPoints; ++i) {
            double x = Math.cos(tempAngle) * radius + centerX;
            double y = Math.sin(tempAngle) * radius + centerY;
            g.fillOval((int)x, (int)y, 5, 5);
            tempAngle += angleIncrement;
    }

  • Unable to draw line touching the y-axis.

    Hi,
    Can anybody suggest how to draw a staright line from the y-axis (touching the y-axis) while drawing a combination graph of line and bar?
    While trying to do show the line is not from the y-axis. The first point is coming in a slight gap.
    Please fing the code.....
    public List getTabularData() {
    ArrayList list = new ArrayList();
    String[] rowLabels = new String[] {"Allocation", "Forecast","Booking", "Loaded"};
    String[] colLabels = new String[] {"03-Jul", "04-Jul", "05-Jul",
    "06-Jul", "07-Jul", "08-Jul",
    "09-Jul", "10-Jul", "11-Jul",
    "12-Jul", "13-Jul", "14-Jul"};
    Double [] [] values = new Double[][]{
    {140.0, 140.0, 140.0, 120.0, 120.0, 120.0, 120.0, 120.0, 120.0, 120.0, 120.0, 120.0},
    {20.0, 42.00, 82.0, 95.0, 102.0, 97.0, 114.0, 124.0, 124.0, 124.0, 124.0, 124.0},
    {0.0, 10.0, 35.0,60.0, 95.0, 110.0, 110.0, 110.0, 110.0,124.0, 124.0, 124.0},
    {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 120.0, 120.0}
    for (int c = 0; c < colLabels.length; c++)
    for (int r = 0; r < rowLabels.length; r++)
    list.add (new Object [] {colLabels[c], rowLabels[r],
    new Double (values[r][c])});
    return list;
    the jspx...
    <dvt:graph id="graph1"
    tabularData="#{backing_abf009page.tabularData}"
    graphType="COMBINATION_VERT_ABS"
    markerDisplayed="true">
    <dvt:o1Axis lineColor="#ff0084"/>
    <dvt:seriesSet defaultLineWidth="1">
    <dvt:series index="0" color="#ffff73"
    markerType="MT_CURVE_LINE" markerShape="MS_DIAMOND" />
    <dvt:series index="1" color="#ff7342"
    markerType="MT_CURVE_LINE" markerShape="MS_DIAMOND"/>
    <dvt:series index="2" color="#94b5ff"
    markerType="MT_CURVE_LINE" markerShape="MS_DIAMOND" />
    <dvt:series index="3" color="#ffff73"
    markerType="MT_BAR" markerShape="MS_DIAMOND" />
    </dvt:seriesSet>
    </dvt:graph>

    It seems it has never been implemented. I tried many different ways but no luck.
    I think it is not possible. You could open a ticket with Oracle Support to get you explained this
    either there is Doc Bug or a Product bug.
    regards
    Jorge

  • Drawing a perfect circle that rotates

    Hi
    I tried to draw a circle while holding down the Shift-key. Then centered it inside a MovieClip named 'circle_mc'
    Every frame I'm rotating it like this:
    circle_mc.rotation += 5;
    That seems pretty simple but the circle is not perfectly round. Why?
    You can see the result here:
    http://boostmode.com/dev/circle/circle.html
    Any ideas?
    Thanks
    Rolf

    I didn't find a solution to drawing the circle withing Flash. However I did manage to get a perfect circle by drawing the circle in Illustrator CC and then copy it and paste it in Flash.
    Thanks for the help. And thanks for duplicating the experiment Ned.
    I'm a little disappointed with Flash drawing capabilities.  
    Heres the new circle drawn in Iluustrator:
    http://boostmode.com/dev/circle/circle2.html
    And the old one drawn in Flash:
    http://boostmode.com/dev/circle/circle.html
    Rolf 

  • Drawing the red circle on the iphone

    Is there some in-built function where I can draw that red alert circle, like what you see when you have a new message or missed calls?

    So I found an easy way to do it, but I have a problem with it.
    I created a subclass of UITabBar in which all I did was override the drawRect method to do nothing. I then added a UITabBarItem with no image or text, but I set the badgeValue and that worked well.
    My issue now is that the badge is too small for what I want on the screen. Does anybody know how I can make it bigger?
    Thanks!

  • Three Touch broken in 4 years

    The third and the last one, obviously. Last month broke my third Ipod Touch in 4 years. White screen and goodbye.
    I can't believe. No more.

    Not physically damaged, the three looks like new, the problem, always, is inside. The first one the screen turn to black: broken, no solution. The second and the third, the screen turn to white and there is no solution. I try to restore, and nothing happens.
    I love this gadget but this was the last one.

Maybe you are looking for