If you are given a graph with the points of a bounded polygon, you can enter the points into this program and get the area. Works for polygons up to 10 points.


Code:

ClrHome
Input "How Many Points?",Z
Disp "Enter the Points"
Disp "Going Counter"
Disp "Clockwise"
If X<=2
Then
   Disp "Please Enter A"
   Disp "Value From 3-10"
Else
   If X=10
   Then
      Input "X1=",A
      Input "Y1=",B
      Input "X2=",C
      Input "Y2=",D
      Input "X3=",E
      Input "Y3=",F
      Input "X4=",G
      Input "Y4=",H
      Input "X5=",I
      Input "Y5=",J
      Input "X6=",K
      Input "Y6=",L
      Input "X7=",M
      Input "Y7=",N
      Input "X8=",O
      Input "Y8=",P
      Input "X9=",Q
      Input "Y9=",R
      Input "X10=",S
      Input "Y10=",T
      {2,2->dim([A]
      {2,2->dim([B]
      {2,2->dim([C]
      {2,2->dim([D]
      {2,2->dim([E]
      {2,2->dim([F]
      {2,2->dim([G]
      {2,2->dim([H]
      {2,2->dim([I]
      {2,2->dim([J]
      A->[A](1,1):B->[A](2,1):C->[A](1,2):D->[A](2,2)
      C->[B](1,1):D->[B](2,1):E->[B](1,2):F->[B](2,2)
      E->[C](1,1):F->[C](2,1):G->[C](1,2):H->[C](2,2)
      G->[D](1,1):H->[D](2,1):I->[D](1,2):J->[D](2,2)
      I->[E](1,1):J->[E](2,1):K->[E](1,2):L->[E](2,2)
      K->[F](1,1):L->[F](2,1):M->[F](1,2):N->[F](2,2)
      M->[G](1,1):N->[G](2,1):O->[G](1,2):P->[G](2,2)
      O->[H](1,1):P->[H](2,1):Q->[H](1,2):R->[H](2,2)
      Q->[I](1,1):R->[I](2,1):S->[I](1,2):T->[I](2,2)
      S->[J](1,1):T->[J](2,1):A->[J](1,2):B->[J](2,2)
      .5((Det([A])+(Det([B])+(Det([C])+(Det([D])+(Det([E])+(Det([F])+(Det([G])+(Det([H])+(Det([I])+(Det([J]))->Y
      Disp "Area=",Y
   Else
      If X=9
      Then
         Input "X1=",A
         Input "Y1=",B
         Input "X2=",C
         Input "Y2=",D
         Input "X3=",E
         Input "Y3=",F
         Input "X4=",G
         Input "Y4=",H
         Input "X5=",I
         Input "Y5=",J
         Input "X6=",K
         Input "Y6=",L
         Input "X7=",M
         Input "Y7=",N
         Input "X8=",O
         Input "Y8=",P
         Input "X9=",Q
         Input "Y9=",R
         {2,2->dim([A]
         {2,2->dim([B]
         {2,2->dim([C]
         {2,2->dim([D]
         {2,2->dim([E]
         {2,2->dim([F]
         {2,2->dim([G]
         {2,2->dim([H]
         {2,2->dim([I]
         A->[A](1,1):B->[A](2,1):C->[A](1,2):D->[A](2,2)
         C->[B](1,1):D->[B](2,1):E->[B](1,2):F->[B](2,2)
         E->[C](1,1):F->[C](2,1):G->[C](1,2):H->[C](2,2)
         G->[D](1,1):H->[D](2,1):I->[D](1,2):J->[D](2,2)
         I->[E](1,1):J->[E](2,1):K->[E](1,2):L->[E](2,2)
         K->[F](1,1):L->[F](2,1):M->[F](1,2):N->[F](2,2)
         M->[G](1,1):N->[G](2,1):O->[G](1,2):P->[G](2,2)
         O->[H](1,1):P->[H](2,1):Q->[H](1,2):R->[H](2,2)
         Q->[I](1,1):R->[I](2,1):A->[I](1,2):B->[I](2,2)
         .5((Det([A])+(Det([B])+(Det([C])+(Det([D])+(Det([E])+(Det([F])+(Det([G])+(Det([H])+(Det([I]))->Y
         Disp "Area=",Y
      Else
         If X=8
         Then
            Input "X1=",A
         Input "Y1=",B
         Input "X2=",C
         Input "Y2=",D
         Input "X3=",E
         Input "Y3=",F
         Input "X4=",G
         Input "Y4=",H
         Input "X5=",I
         Input "Y5=",J
         Input "X6=",K
         Input "Y6=",L
         Input "X7=",M
         Input "Y7=",N
         Input "X8=",O
         Input "Y8=",P
         {2,2->dim([A]
         {2,2->dim([B]
         {2,2->dim([C]
         {2,2->dim([D]
         {2,2->dim([E]
         {2,2->dim([F]
         {2,2->dim([G]
         {2,2->dim([H]
         A->[A](1,1):B->[A](2,1):C->[A](1,2):D->[A](2,2)
         C->[B](1,1):D->[B](2,1):E->[B](1,2):F->[B](2,2)
         E->[C](1,1):F->[C](2,1):G->[C](1,2):H->[C](2,2)
         G->[D](1,1):H->[D](2,1):I->[D](1,2):J->[D](2,2)
         I->[E](1,1):J->[E](2,1):K->[E](1,2):L->[E](2,2)
         K->[F](1,1):L->[F](2,1):M->[F](1,2):N->[F](2,2)
         M->[G](1,1):N->[G](2,1):O->[G](1,2):P->[G](2,2)
         O->[H](1,1):P->[H](2,1):A->[H](1,2):B->[H](2,2)
         .5((Det([A])+(Det([B])+(Det([C])+(Det([D])+(Det([E])+(Det([F])+(Det([G])+(Det([H]))->Y
            Disp "Area=",Y
         Else
            If X=7
         Then
            Input "X1=",A
         Input "Y1=",B
         Input "X2=",C
         Input "Y2=",D
         Input "X3=",E
         Input "Y3=",F
         Input "X4=",G
         Input "Y4=",H
         Input "X5=",I
         Input "Y5=",J
         Input "X6=",K
         Input "Y6=",L
         Input "X7=",M
         Input "Y7=",N
         {2,2->dim([A]
         {2,2->dim([B]
         {2,2->dim([C]
         {2,2->dim([D]
         {2,2->dim([E]
         {2,2->dim([F]
         {2,2->dim([G]
         A->[A](1,1):B->[A](2,1):C->[A](1,2):D->[A](2,2)
         C->[B](1,1):D->[B](2,1):E->[B](1,2):F->[B](2,2)
         E->[C](1,1):F->[C](2,1):G->[C](1,2):H->[C](2,2)
         G->[D](1,1):H->[D](2,1):I->[D](1,2):J->[D](2,2)
         I->[E](1,1):J->[E](2,1):K->[E](1,2):L->[E](2,2)
         K->[F](1,1):L->[F](2,1):M->[F](1,2):N->[F](2,2)
         M->[G](1,1):N->[G](2,1):A->[G](1,2):B->[G](2,2)
         .5((Det([A])+(Det([B])+(Det([C])+(Det([D])+(Det([E])+(Det([F])+(Det([G]))->Y
               Disp "Area=",Y
         If X=6
         Then
            Input "X1=",A
         Input "Y1=",B
         Input "X2=",C
         Input "Y2=",D
         Input "X3=",E
         Input "Y3=",F
         Input "X4=",G
         Input "Y4=",H
         Input "X5=",I
         Input "Y5=",J
         Input "X6=",K
         Input "Y6=",L
         {2,2->dim([A]
         {2,2->dim([B]
         {2,2->dim([C]
         {2,2->dim([D]
         {2,2->dim([E]
         {2,2->dim([F]
         A->[A](1,1):B->[A](2,1):C->[A](1,2):D->[A](2,2)
         C->[B](1,1):D->[B](2,1):E->[B](1,2):F->[B](2,2)
         E->[C](1,1):F->[C](2,1):G->[C](1,2):H->[C](2,2)
         G->[D](1,1):H->[D](2,1):I->[D](1,2):J->[D](2,2)
         I->[E](1,1):J->[E](2,1):K->[E](1,2):L->[E](2,2)
         K->[F](1,1):L->[F](2,1):A->[F](1,2):B->[F](2,2)
         .5((Det([A])+(Det([B])+(Det([C])+(Det([D])+(Det([E])+(Det([F]))->Y
                  Disp "Area=",Y
               Else
               If X=5
         Then
            Input "X1=",A
         Input "Y1=",B
         Input "X2=",C
         Input "Y2=",D
         Input "X3=",E
         Input "Y3=",F
         Input "X4=",G
         Input "Y4=",H
         Input "X5=",I
         Input "Y5=",J
         {2,2->dim([A]
         {2,2->dim([B]
         {2,2->dim([C]
         {2,2->dim([D]
         {2,2->dim([E]
         A->[A](1,1):B->[A](2,1):C->[A](1,2):D->[A](2,2)
         C->[B](1,1):D->[B](2,1):E->[B](1,2):F->[B](2,2)
         E->[C](1,1):F->[C](2,1):G->[C](1,2):H->[C](2,2)
         G->[D](1,1):H->[D](2,1):I->[D](1,2):J->[D](2,2)
         I->[E](1,1):J->[E](2,1):A->[E](1,2):B->[E](2,2)
         .5((Det([A])+(Det([B])+(Det([C])+(Det([D])+(Det([E]))->Y
                     Disp "Area=",Y
                  Else
                     If X=4
         Then
            Input "X1=",A
         Input "Y1=",B
         Input "X2=",C
         Input "Y2=",D
         Input "X3=",E
         Input "Y3=",F
         Input "X4=",G
         Input "Y4=",H
         {2,2->dim([A]
         {2,2->dim([B]
         {2,2->dim([C]
         {2,2->dim([D]
         A->[A](1,1):B->[A](2,1):C->[A](1,2):D->[A](2,2)
         C->[B](1,1):D->[B](2,1):E->[B](1,2):F->[B](2,2)
         E->[C](1,1):F->[C](2,1):G->[C](1,2):H->[C](2,2)
         G->[D](1,1):H->[D](2,1):A->[D](1,2):B->[D](2,2)
         .5((Det([A])+(Det([B])+(Det([C])+(Det([D]))->Y
                        Disp "Area=",Y
                     Else
                        
                        If X=3
         Then
            Input "X1=",A
         Input "Y1=",B
         Input "X2=",C
         Input "Y2=",D
         Input "X3=",E
         Input "Y3=",F
         {2,2->dim([A]
         {2,2->dim([B]
         {2,2->dim([C]
         A->[A](1,1):B->[A](2,1):C->[A](1,2):D->[A](2,2)
         C->[B](1,1):D->[B](2,1):E->[B](1,2):F->[B](2,2)
         E->[C](1,1):F->[C](2,1):A->[C](1,2):B->[C](2,2)
         .5((Det([A])+(Det([B])+(Det([C]))->Y
               Disp "Area=",Y


Yeah, I need to learn how to optimize it. I don't know how to do this other than hardcoding every value 3-10. Resulting in a ridiculously large program for what it does

I appreciate feedback. Criticize it as much as you want. I am fairly new to code.


---------------------------------------------------------------------------------------------------------------------
EDIT!!!
Just finished making that code shorter. The new code comes in at about 4.3% of the original size in terms of bytes.

I still want feedback

If you care the code is posted below. (Ti-84 Silver edition [monochrome])


Code:

Input "Nmbr Of Points=",Z
Disp "Enter Points"
Disp "Going Counter ClockWise"
Input "X=?",A
Input "Y=?",B
0->dim(L1
{2,2}->dim([A]
A->[A](1,1)
B->[A](2,1)
For(N,2,Z)
   Prompt X
   Prompt Y
   X->[A](1,2)
   Y->[A](2,2)
   det([A])->L1(dim(L1)+1)
   X->[A](1,1)
   Y->[A](2,1)
End
A->[A](1,2)
B->[A](2,2)
det([A])->L1(Dim (L1)+1)
sum(L1)*.5->C
Disp "Area=",C
Looks great! I'm pretty sure a bunch of this can be optimized, but it still looks good!
Here’s what I entered on my TI-89.


Code:

area()
Prgm
ClrIO
Disp "Enter in circular order."
Disp "Enter nbr of points.",p
newList(p)->xx
newList(p)->yy
For a,1,p
ClrIO
string(a)->as
Input "Enter x"&as,x
x->xx[a]
Input "Enter y"&as,y
y->yy[a]
EndFor
0->t
p->j
For a,1,p
t+xx[j]*yy[a]-yy[j]*xx[a]->t
a->j
EndFor
ClrIO
Disp "Area"
Disp abs(t/2)*1.
EndPrgm
Jasonpm wrote:
Criticize it as much as you want.

It's garbage. <3

Welcome to Cemetech! Smile I hope that practing coding can make your code look even better. One thing to note is that your code is a bunch of copy/paste of essentially the same sections. You can use a For Loop to iterate over the elements in the matrix as needed, without having a bunch of similar cases. Hope this helps. Smile
MateoConLechuga wrote:
Jasonpm wrote:
Criticize it as much as you want.

It's garbage. <3

Welcome to Cemetech! Smile I hope that practing coding can make your code look even better. One thing to note is that your code is a bunch of copy/paste of essentially the same sections. You can use a For Loop to iterate over the elements in the matrix as needed, without having a bunch of similar cases. Hope this helps. Smile


Thanks for advice i will research for loop and hopefully improve it
Jasonpm

Did you completely skip what I posted above for my TI89.
dave1707 wrote:
Jasonpm

Did you completely skip what I posted above for my TI89.

Yes I did. Not being rude, but there were multiple errors and I am not too experienced with the 89's so it wasn't worth my time.
This looks really hard to optimize. I might try to, though.
Here’s my TI89 code above converted to my TI84 Plus Silver Edition.

Code:

ClrHome
Disp "ENTER POINTS IN"
Disp "CIRCULAR ORDER"
Disp "NBR OF POINTS  ",P
For A,1,P
ClrHome
Input "X ",X
Input "Y ",Y
X->L1(A
Y->L2(A
End
0->T
P->J
For A,1,P
T+L1(J)*L2(A)-L2(J)*L1(A)->T
A->J
End
ClrHome
Disp "AREA",abs(T/2)
My "fun" little contribution:

Code:
:L1+L2i
:conj(Ans)+ΔList(cumSum(augment(Ans,{Ans(1
:abs(sum(imag(Ans²/4
*Legoman314's head explodes due to the sheer force of optimization emanating from this post*
How? It's just amazing how you can find the area of a polygon in just 3 lines. Great work!

Code:
L1+L2i
.5abs(sum(imag(Ansconj(ΔList(cumSum(augment(Ans,{Ans(1


This may be optimal. It's strangely satisfying to have 9 open-parentheses on a line.
Actually, all that’s needed is the one line posted by lirtosiast. If you have to enter the x,y values into the lists L1 and L2, you might as well just enter the number and imaginary number inside the brackets { } and press enter. That will put the result in Ans just like the line L1+L2i does. So that brings it down to 1 line of code.

Quote:
.5abs(sum(imag(Ansconj(ΔList(cumSum(augment(Ans,{Ans(1
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement