This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
(Moderators: fry, REAS)
   Drawing an equilateral triangle
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Drawing an equilateral triangle  (Read 635 times)

Drawing an equilateral triangle
« on: Sep 20th, 2004, 6:20pm »

I'm trying to figure out the coordinates for an equilateral triangle, positioned in the center of a screen, with all corners extending 255 pixels from the center.  Let's say the screen is 600x600.  
I failed Geometry in high school (I know...), so I'm sure there is a simple formula I'm not aware of.  Any suggestions?

WWW Email
Re: Drawing an equilateral triangle
« Reply #1 on: Sep 20th, 2004, 8:28pm »

Ok (taking deep breath)...
* Instant gratification
 Assuming triangle is pointing up:
 point apex
 point left base
 point right base
* In general: equilateral triangle inscribed in circle with radius R, centered at point (Xc,Yc),
apex at angle ALPHA from vertical:
 point 1
 point 2
 point 3
* Even more general: N-sided regular polygon inscribed in circle with radius R, centered at point (Xc,Yc), first point at angle ALPHA from vertical:
 point i (from 0 to N-1):
* Deeper background, think about it:
 point on circle centered on (Xc,Yc) with radius R,
 at angle ALPHA from vertical
Hmm, triangle with corners extending 255 pixels from the center. Colour triangle?
Anyway, have fun. Don't forget to share your work!
« Last Edit: Sep 20th, 2004, 8:30pm by Frederik »  

Re: Drawing an equilateral triangle
« Reply #2 on: Sep 21st, 2004, 7:03pm »

You are right - 'color triangles'.  
I implemented the first set of formulas you provided.  
Here is initial sketch: www.friendlycommunity.net/josh/triangles.html
Click on part of the image.  A triangle is drawn which plots the RGB values of the selected pixel, and draws the triangle in corresponding color.  The point apex is red, the right is green, the left is blue.  
Any comments appreciated.
Here's the code:
void setup()
size(700, 700);
BImage c = loadImage("http://www.friendlycommunity.net/josh/bug4.jpg");
image(c, -300, 500);
BImage d = loadImage("http://www.friendlycommunity.net/josh/greenery2.jpg");
image(d, 300, 500);
color b;
void mousePressed()
b = get(mouseX, mouseY);
void mouseDragged()
b = get(mouseX, mouseY);
void loop()
 int x1 = width/2;
 int y1 = int(height/2-(red(b)*1.25));
 int x2 = int(width/2-(green(b)*1.25)*cos(PI/6));
 int y2 = int(height/2+(green(b)*1.25)*sin(PI/6));
 int x3 = int(width/2+(blue(b)*1.25)*cos(PI/6));
 int y3 = int(height/2+(blue(b)*1.25)*sin(PI/6));
Pages: 1 

« Previous topic | Next topic »