Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
1

Custom Angled Triangles Question

Participant ,
Nov 20, 2013 Nov 20, 2013

I'm quite suprised that powerful Illustrator does not have any easy solution for creating custom angled triangles. Is there anybody help me to create a custom angle triangle script ?

Thank you,

Best Regards.

TOPICS
Scripting
5.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Nov 21, 2013 Nov 21, 2013

Triangle Maker (Side, Angle, Angle)

// Triangle Maker (Side, Angle, Angle)

// Carlos Canto - 11/21/13;

// http://forums.adobe.com/thread/1339420?tstart=0

var idoc = app.activeDocument;

var s_ssa = Window.prompt ('Enter 1 Side in points, 2 Angles in degrees, (Side, Angle1, Angle2)', '120, 30, 57', 'Triangle Maker');

var a_ssa = s_ssa.split(','); // turn into an array

var side = parseFloat (a_ssa[0]);

var angle1 = parseFloat (a_ssa[1]);

var angle2 = parseFloat (a_ssa[2]);

if (angle1+angle2<180) {

    var pat

...
Translate
Enthusiast , Apr 02, 2025 Apr 02, 2025

Inspired by Carlos' ideas, I combined the two scripts into one — TriangleMaker. It now has a triangle settings dialog and previews.

TriangleMaker.jpgexpand image

Translate
Adobe
Community Expert ,
Nov 20, 2013 Nov 20, 2013

please elaborate, do you want to provide let's say 2 angles and build a triangle?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2013 Nov 20, 2013

Yes exactly, I have noticed that there is no such script around the net. I don't have any Illustrator Scripting experience, I can only modify script with the help of scripting dictionaries:)

I have found an example in Adobe Illustrator Scripting Guide;

Basically I want two input box for degree and script should automatically creates a triangle. ( In fact it would be great if we would enter the values of edges (a,b) )

// Create 45 Degree Triangle

var doc = app.activeDocument;

var sel = doc.selection;

dw  = doc.width;

dh = doc.height;

wc= dw /2;

hc = dh *-0.5;

if ( app.documents.length > 0 ) {

var triangleGroup = app.activeDocument.groupItems.add();

// Create a triangle and add text, the new art is created inside the group

var trianglePath = triangleGroup.pathItems.add();

trianglePath.setEntirePath( Array( Array(0, 100), Array(100, 0),

Array(0,0) ) );

trianglePath.closed = true;

trianglePath.stroked = true;

trianglePath.filled =true;

trianglePath.strokeWidth = 3;

trianglePath.position = Array(wc,hc);

}

Would you please help me, I would be really grateful:)))

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2013 Nov 20, 2013

( In fact it would be great if we would enter the values of edges (a,b) )

by "edges", do you mean "sides"?, if so we need a third variable for angle, (a,b,c) (side, side, angle)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2013 Nov 20, 2013

Yes, sides. Since the sum of internal angles of a triangle is 180 degree, I guess we do not need. Or am I missing out something? (Sorry I did not have any math class:) )

I think we need something like Scalene Triangle. But for the side length do we need to know their values? Or the math itself automatically gives the rest.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2013 Nov 20, 2013

look here, we need at leat 3 values of any kind, mix and match sides and/or angles

http://ostermiller.org/calc/triangle.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2013 Nov 20, 2013

Hımm, ok you right, It's ok then but how:))) All I want is to create a triangle which I can enter custom values, I guess It would be very useful for lots of people. Is it possible to continue and modify with the script below?

// Create 45 Degree Triangle

var doc = app.activeDocument;

var sel = doc.selection;

dw  = doc.width;

dh = doc.height;

wc= dw /2;

hc = dh *-0.5;

if ( app.documents.length > 0 ) {

var triangleGroup = app.activeDocument.groupItems.add();

// Create a triangle and add text, the new art is created inside the group

var trianglePath = triangleGroup.pathItems.add();

trianglePath.setEntirePath( Array( Array(0, 100), Array(100, 0),

Array(0,0) ) );

trianglePath.closed = true;

trianglePath.stroked = true;

trianglePath.filled =true;

trianglePath.strokeWidth = 3;

trianglePath.position = Array(wc,hc);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 20, 2013 Nov 20, 2013

And also as you have written (a,b,c) (side, side, angle) we can do vice versa like angle,angle,side. I tried it on calculator you have sent me.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2013 Nov 21, 2013

Triangle Maker (Side, Side, Angle)

// Triangle Maker (Side, Side, Angle)

// Carlos Canto - 11/21/13;

// http://forums.adobe.com/thread/1339420?tstart=0

var idoc = app.activeDocument;

var s_ssa = Window.prompt ('Enter 2 Sides in points, Angle in degrees, (Side, Side, Angle)', '100, 120, 30', 'Triangle Maker');

var a_ssa = s_ssa.split(','); // turn into an array

var side1 = parseFloat (a_ssa[0]);

var side2 = parseFloat (a_ssa[1]);

var angle = parseFloat (a_ssa[2]);

var path1 = idoc.pathItems.add();

var p0 = [0,0];

var p1 = [side1,0];

var p2 = getSideAngePoint (side2, angle);

path1.setEntirePath ([p0, p1, p2]);

path1.closed = true;

// returns point 2 given a segment length and its angle, point 1 is [0,0]

function getSideAngePoint(side, angle) {

    var rads = angle*Math.PI/180;

    var px = Math.cos(rads)*side;

    var py = Math.sin(rads)*side;

  return [px, py];

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2013 Nov 21, 2013

Triangle Maker (Side, Angle, Angle)

// Triangle Maker (Side, Angle, Angle)

// Carlos Canto - 11/21/13;

// http://forums.adobe.com/thread/1339420?tstart=0

var idoc = app.activeDocument;

var s_ssa = Window.prompt ('Enter 1 Side in points, 2 Angles in degrees, (Side, Angle1, Angle2)', '120, 30, 57', 'Triangle Maker');

var a_ssa = s_ssa.split(','); // turn into an array

var side = parseFloat (a_ssa[0]);

var angle1 = parseFloat (a_ssa[1]);

var angle2 = parseFloat (a_ssa[2]);

if (angle1+angle2<180) {

    var path1 = idoc.pathItems.add();

    var p0 = [0,0];

    var p1 = getSideAngePoint (side, angle1);

    var C = get3rdAngle (angle1, angle2);

    var teta = getTempAngle (C); // the one that forms a Right Angle Triangle, down from Side Point 2 and hipotenuse

    var adj = p1[1];

    var opo = oposite (adj, teta);

    var p2x = p1[0]+opo;

    var p2 = [p2x,0];

    path1.setEntirePath ([p0, p1, p2]);

    path1.closed = true;

}

else {alert('both angles combined should be less than 180');}

// returns point 2 given a segment length and its angle, point 1 is [0,0]

function getSideAngePoint(side, angle) {

    var rads = angle*Math.PI/180;

    var px = Math.cos(rads)*side;

    var py = Math.sin(rads)*side;

  return [px, py];

}

// given 2 angles, return the 3rd angle

function get3rdAngle(angle1, angle2) {

    return 180-angle1-angle2;

}

// return "TETA" in a complimentary Right Angle Triangle

function getTempAngle(thirdAngle) {

    return 90-thirdAngle;

}

// returns the Oposite side in the complimentary Right Angle Triangle

function oposite (adj, angle) {

    //tan teta = oposite/adjacent

    var rads = angle*Math.PI/180;

    var op = Math.tan (rads)*adj;

    return op;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2013 Nov 21, 2013

Thanks a million:) it works like a charm..with your permission I would like to share it through my web site with your name. You're great:)))

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2013 Nov 21, 2013

you're welcome, go ahead and share it

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2013 Nov 21, 2013

by the way, what do you do? what's your need to automate the creation of triangles?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 21, 2013 Nov 21, 2013

http://creativetuts.com/tutorials/illustrator-tutorials/custom-angled-triangle-maker-script-for-ai/

I was trying to create complex geometrical patterns in Cinema 4D. I have found one example and decided to try it on Illustrator for the base seed. But It was containing a triangle with 30,30,120 degrees. Then I have searched around the net found some tutorials but they were so long and they were not practical at all. I'm sure that this script would help some other people also. Thank you very much again.

(By the way one of my friend asked if it has an ability to work with polygons. (with custom side count option and entering their angle values. Just saying may be you would create a plugin or a more complex script doing these kind of stuff and sell it. I would gladly buy it...Just an idea...)   

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 21, 2013 Nov 21, 2013

cool, I'm always curios about the script usage and the type of art being made with it.

the two scripts posted above only work with Triangles, polygons need to be treated separately.

By the way one of my friend asked if it has an ability to work with polygons. (with custom side count option and entering their angle values. Just saying may be you would create a plugin or a more complex script doing these kind of stuff and sell it. I would gladly buy it...Just an idea...

this one is free of charge, but I gladly take donations (if you wish, paypal me at this account xtaurio at yahoo dot com)

#target Illustrator

//  script.name = polygonBySide.jsx;

//  script.description = creates a polygon based on side length;

//  script.requirement = an open document;

//  script.parent = CarlosCanto;  // 11/21/13;

//  script.elegant = false;

if (app.documents.length>0) polygonBySide ();

else alert ("no document to draw the polygon");

function polygonBySide() {

    var title = "Create Polygon by Side";

    var sideLen = Number(prompt ("Enter Side Length in Points", 20, title));

    var numberOfSides = Number(prompt ("Enter number of sides", 5, title));

    //var s = 2*r*Math.sin(Math.PI/n); // side length = 2*radius*sin(180 deg/number of sides)

    var radius = sideLen/(2*Math.sin(Math.PI/numberOfSides));

    var idoc = app.activeDocument;

    var ctr = idoc.activeView.centerPoint;

    var ipoly = idoc.pathItems.polygon (ctr[0], ctr[1], radius, numberOfSides);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 22, 2013 Nov 22, 2013

Thanks again, http://creativetuts.com/tutorials/illustrator-tutorials/polygon-by-side-ai-script/

I have also added a donation button linked to your account. Hope it's ok...

(By the way again it would be even better if it would have an Angle option too..But I guess it's very hard, according to side number it should create dialog boxes for to enter each angle and side. And I guess it's impossible to make it closed polygon.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2013 Nov 22, 2013

thanks,

that's correct "regular" polygons have fixed angles, i.e. for rectangles, each angle must be 90 degrees, otherwise it becomes something else...it's possible to script it based on angles but it will only be practical if you want odd shapes.

thanks again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 06, 2025 Mar 06, 2025

I've been looking for a solution for this myself recently – I need to create triangles with specific angles for some conical cutter templates – I know I can do it with transform/rotate options, but would be great to have an inbuilt option on the polygon tool, or a new 'triangle' tool where you can specify inner angles!? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 06, 2025 Mar 06, 2025

Hello @bnjmngrn,

I understand that this functionality is important to you. Would you mind creating a UserVoice for this feature request (https://adobe.ly/41HBKZG) and adding your comments there? Doing this will help us prioritize this request, and you will be notified of any updates.


Also, try the suggestions shared in this tutorial (https://adobe.ly/4he1ocZ) and share your observations.

Feel free to reach out if you have more questions or need assistance. We'd be happy to help.

 

Anubhav

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 02, 2025 Apr 02, 2025

Inspired by Carlos' ideas, I combined the two scripts into one — TriangleMaker. It now has a triangle settings dialog and previews.

TriangleMaker.jpgexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2025 Apr 02, 2025

Thank you! Love it, I like the Preview and the text option! Maybe in the future a Convert to Shape option (although it is easy to do yourself)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 02, 2025 Apr 02, 2025

It's easy to do this yourself, but it's also easy to include this command in a script. But why make a custom triangle a dynamic shape?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2025 Apr 02, 2025

It is not a big thing, but I like the flexibility of the options in the Transform panel after creating the triangle.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2025 Apr 02, 2025

Let me give an example, a triangle manipulated in the Appearance Panel to create a pattern can be easily changed by modifying some shape attributes in something totally different.

Shape flexibility.pngexpand image

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 02, 2025 Apr 02, 2025

Since only some triangles can be converted into a live shape (polygon specifically), I don’t think the script should even try. I have Object > Shape > Convert to Shape even assigned to Cmd/Ctrl + 9 , I’m good 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines