[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


>>
I don't know how to calculate the area of a polygon on paper, much less write a program for it.
When was I supposed to learn this? Geometry class? Trigonometry? In any case, if I learned it, I forgot it.
>>
easy
>>
>>108823328
Something about edge cases and degenerate polygons and numerical instability. I hate computational geometry.
>>
File: Kurisu.jpg (160 KB, 640x960)
160 KB JPG
>>108823436
do it then
>>
>>108823471
already did. easy.
>>
>>108823328
No, you literally can't solve this with just the coordinates of the corners, unless you're limiting it to solve only convex polygons. There is no way to know what order the lines between the corners go in if it's a concave polygon.

Sage goes in all fields
>>
>>108823531
>There is no way to know what order the lines between the corners go
The order in which they were passed, retard.
>>
>>108823543
That's making an assumption that may not necessarily be true though. That needs to be part of the specification, not just an unwritten assumption.
>>
>>108823328
what are the max and min number of points, please
>>
>>108823561
>That's making an assumption that may not necessarily be true though
Necessarily true by the definition of the function. Passing the vertices in the wrong order is user error.
>>
>>108823543
If you're a programmer I bet your manager loves you because you can put out code that seemingly works even if it actually doesn't do what was requested >>108823561 is right and if you make assumption like that you're a very dangerous programmer if you work on anything important.
>>
File: polygon.png (16 KB, 1083x631)
16 KB PNG
>>108823488
Post the solution then.

>>108823531
The lines are drawn in the order the corners are in the array(or whatever data structure your language uses)(Assuming it's a function and receives them as a parameter. If they are read as user input, then then order in which the points are read). And then the line that connects the last corner to the first one.
So if you get the coordinates of the points A, B, C and D in this order, this would be the resulting polygon
>>
>>108823591
>retards keep confabulating clownishly tenuous cope because they can't complete a task
>>
File: maid_prog.png (373 KB, 580x386)
373 KB PNG
oh I know this one
https://en.wikipedia.org/wiki/Shoelace_formula
def polygon_area(points: List[List[int]]) -> int:
n = len(points)
area = 0
for i in range(n):
x1, y1 = points[i]
x2, y2 = points[(i + 1) % n] # wrap around
area += x1 * y2 - x2 * y1
return abs(area) / 2
>>
>>108823604
Returns a wrong result for infinitely many perfectly good polygons.
>>
File: polygon.png (16 KB, 1083x631)
16 KB PNG
>>108823571
The minimum number of points is 0. But anything less than 3, you can just have the program return 0. There is no maximum number of points.

>>108823531
>>108823561
>>108823591
You're deliberately missing the point of this thread. We're not writing enterprise software here. If something seems too vague, either just ask for clarification, or make your own definition. Don't just give up on the whole thing.

Also, if you want even more clarification, I have colored magenta want I would define as the area in >>108823598
>>
File: 1778786623490.jpg (84 KB, 640x640)
84 KB JPG
>>108823645
Thank you.

I propose a solution that creates a box area around the maximal 4 points. That will be the max area. The it subtracts the whitespace area. That is the answer for you.

Now I need an algorithm. Hmmm
>>
>>108823645
>You're deliberately missing the point of this thread
No, it's my autism.
>>
File: polygon.png (16 KB, 1083x631)
16 KB PNG
>>108823604
Congratulations for being the first one in this thread to actually try solving it. But the solution isn't correct. Take a look at >>108823645. Your program would treat the area of one of the triangles as being negative. It would essentially output this area.
>>
>>108823689
Attempting to solve this is a testament to the lack of knowledge needed to solve this.
>>
>>108823666
How would you compute the whitespace area?
>>
>>108823328
To what level of precision?
>>
>>108823328
just sample the AABB stretched over the polygon points. test each sample for being inside/outside the polygon by calculating its winding number. sample as densely as needed.
>>
>>108823328
Not doing your homework ranjesh
>>
>>108823740
go left to right on polygon point intervals
>>
>>108823742
Doesn't really matter. Even single decimal precision would be fine.
>>
>>108823328
i'm too dumb for this shit, I'll let you autists solve this shit while i reap the reward
>>
>>108823787
>Doesn't really matter
Well, if it doesn't matter, then I just upscale the coordinates by a very large number, round the results into 128-bit integers then do some Monte-Carlo sampling, testing random points to see if they're inside or outside the polygon by casting horizontal rays and counting the edge crossings. What do I win?
>>
>>108823911
>casting horizontal rays and counting the edge crossings
this shit is jank af. tripped me way too many times, even with casting several random rays and voting. winding number algorithm is the way to go.
>>
>>108823946
It works very well with integer coordinates and integer arithmetic.
>>
>>108823328
i solved it by typing the prompt into an LLM
now what
>>
>>108823911
Nothing is stopping you, but you have to actually write a program that implements this
>>
>>108824003
There's no need to. I know it would work (given your very loose specifications about precision) and the description I gave is enough for anyone who cares to implement it.
>>
>>108823992
>i solved it by typing the prompt into an LLM
No, you didn't, because token shitters can't do it, either. I bet OP was specifically intending to bait retards like you into posting broken AI slop and embarrass themselves.
>>
>>108824045
oh, is this prompt supposed to start an argument about edge cases and definitions and shit instead of testing whether you know about that one specific formula?
i fucking hate these snide little programming gotchas
>>
File: 1778790180170.jpg (170 KB, 1756x1317)
170 KB JPG
>>108823666
I changed my mind.

The max area is good for sanity checking

But we should break this into triangles first and sum their areas
>>
>>108824075
>jeet seethes profusely because his retarded token shitter brain substitute can't actually code
>>
>>108824097
What makes you think breaking down arbitrary self-intersecting polygons into triangles is any easier than the original problem?
>>
File: 1778790570255.jpg (32 KB, 495x619)
32 KB JPG
>>108824110

cus triangle areas are computed with a formula

>sort them top to bottom, left to right
>get anchor/first node
>get two next nodes
>.5 * base * height (the formula)
>those two last nodes make up two sides of the next triangle
>scan for the 3rd point
>add the area to the global sum
>continue until one node remains
>>
>>108824139
Lol.
>>
File: 1778790738672.png (63 KB, 600x800)
63 KB PNG
>>108824146
why wouldn't this work?
>>
This is literally highschool geometry.
>>
File: 1778791045702.jpg (67 KB, 1536x1024)
67 KB JPG
oh fuck I didn't think of this. But duck.ai did
>>
Sex with Kurisu
>>
>>108823328
1. Rescale to integer coordinates
2. https://en.wikipedia.org/wiki/Pick%27s_theorem
>>
>>108823406
normally when you write software you might not know exactly how to do something, but thats part of the fun.
if you read the bottom of the OP image you might notice the word 'solve', the implication is that it is not necessarily supposed to be obvious.

a convex polygon i would say seems pretty easy, you take 3 points as a triangle, calc the area, then remove the middle point from the list. work down until you have 3 left then one more area you are done. add them up

>>108823598
this seems impossible and i will not bother to even think about it, despite what i said earlier.
>>
>>108823689
>>108824281
ok how about, you take the three points to make your triangle, and then you get the line equation for the lines of the outside points, and if they cross, then you know you replace one of the points to calculate the closed triangle.
seems pretty simple to me. next challenge please
>>
>>108823328
I can't be bothered to write out the program or think about this for more than 5 seconds, but my first idea is to split the polygon into triangles and then find the areas of all the triangles and then add them up

damn fuck you anon I'm really sleep deprived and I just wanna go to bed but now I'm going to be laying awake trying to design a program to do this in my head
>>
>>108824320
Behold everyone, this is the sort of hyper obsessive autistic brain you need to be good at problem solving. Poor anon can't even sleep because his brain doesn't have an off switch
>>
ok so it's the sum of all the 2x2 determinants divided by two. Makes sense

I did not see that coming.
>>
>>108824438
>i know this because token shitter said so
>>
>>108824139
>>108824151
>>108824320
This wouldn't work for concave polygons.

>>108824252
Only if you write an implementation that also works for polygons that cross themselves, like the one posted in this thread.

>>108824319
Could you reformulate this? What do you mean by "lines of the outside points"?
>>
>>108824502
Wikipedia is a clanker?
>>
>>108824518
uhhhh keep track of the sign with the even odd rule, split the polygon, calculate area and sum? I think that would work, prolly runs like shit because you have to check every segment against every other segment or at least every segment in a bounding box
>>
>>108823598
That is not a polygon.
>>
>>108824518
ploygons that cross themselves are just the sum of equivalent standalone polygons
also why would I care about knowing how to solve this? I would just ask my clanker to do it
do you know how to build a calculator at the hardware level?
>>
>>108824756
>why do white people climb mountains? Ain't shit up there
>>
>>108824729
It is a polygon, just not a simple one. I never said that the polygon had to be simple.

>>108824756
>do you know how to build a calculator at the hardware level?
You make that sound like something that's hard to do. It's just basic digital electronics. If you are neither able to nor interested in doing stuff like this, why are you even on this board?
>>
>>108823406
>>108823531
why is modern /g/ so excited to post about how retarded they are? how do retards like you even end up on a tech board?
>>
File: simple polygon.png (74 KB, 1335x356)
74 KB PNG
>>108824853
>I never said that the polygon had to be simple.
yes you did
if you want complex polygons, you have to specify that
>>
>>108823328
Dunno, but when I need to know, I’ll be able to figure it out in under 15 minutes, so I’m good.
>>
>>108825031
>you have to explicitly state that certain arbitrary restrictions don't exist
God, I hate modern /g/ so much sometimes, using LLMs as a source to perpetuate confirmation bias
>>
>>108825076
>the clanker called out my sleight of hand
yeah it's not looking good for the future of malignant narcissists like you
>>
>>108824990
I'm not excited. I am learning trigonometry right now.
>>
>>108823645
>You're deliberately missing the point of this thread.

Don't be vague in a blatant "gotcha" thread and expect to not get called out for it.

But for the sake of your question I'm going to assume that the vertices are connected in the order they were provided, in which case the shoelace formula would work for all simple polygons (convex and concave) and also usually works for self-overlapping polygons.

I'm not going to write a simple program implementing the shoelace formula because fuck you for posting retarded gotcha threads like this.

https://en.wikipedia.org/wiki/Shoelace_formula
>>
>>108823328
library(png)
a=commandArgs(T);x=readPNG(a[1]);t=ifelse(length(a)>1,as.numeric(a[2]),.12)
if(length(dim(x))<3)x=array(rep(x,3),c(dim(x),3))
x=x[,,1:3];h=dim(x)[1];w=dim(x)[2]
b=(x[1,1,]+x[1,w,]+x[h,1,]+x[h,w,])/4
m=rowSums((array(b,c(h,w,3),T)-x)^2,dims=2)>t^2
v=matrix(F,h,w);qx=integer(h*w);qy=integer(h*w);l=1;r=0
add=function(i,j){if(i>=1&&i<=h&&j>=1&&j<=w&&!v[i,j]&&!m[i,j]){r<<-r+1;qx[r]<<-i;qy[r]<<-j;v[i,j]<<-T}}
for(i in 1:h){add(i,1);add(i,w)}
for(j in 1:w){add(1,j);add(h,j)}
while(l<=r){i=qx[l];j=qy[l];l=l+1;add(i-1,j);add(i+1,j);add(i,j-1);add(i,j+1)}
cat(sum(!v),"\n")



Rscript area.R polygon.png
>>
>>108823328
CAD From Scratch [17] | Constrained Delaunay Triangulations

youtu.be/_Pe-Raurn34
>>
>shoelace formula
holy fucking brainlets. Just call it a determinant. Jfc
>>
>>108823328
>it's
shan't
>>
>>108826166
>he thinks everyone on this anonymous gaussian shoelace-tying forum has studied linear algebra
who's the brainlet here
>>
>>108823328
My wife Kurisu
>>
>>108826281
it's more a dab on the people "teaching" this stuff to CS lovers

I have a degree in physics
>>
File: 1769685375117007.jpg (515 KB, 2900x1951)
515 KB JPG
>>
>>108825331
>the zoomoid tried to use zoomoid slang as an argument
Yeah, future's not looking good for you broccoli heads.
>>
>>108825031
Did you really just try to use poogle "AI overview" to prove your point lmao
>>
>>108824990
At least the one anon (or someone in their stead) is trying to solve it after getting some push back
>>108824518
I'm pretty sure you can use triangulation still, it just requires more effort because concave is neg and convex can have additional triangles in it.
Regardless, here is my solution
def meme_question(*coords):     
total = 0
for i, (x1,y1) in enumerate(coords):
x2,y2 = coords[(i + 1) % len(coords)]
total += x1*y2 - y1*x2
return abs(total) / 2
>>
>>108826549
>after getting some push back
hello chatgpt
>>
>>108825362
You have to be atleast 18 years old to post.
>>
>>108826719
I am a 42 year old man.
>>
>>108823328
Are there any constraints on the time complexity of the algorithm? I can probably think of something but it would probably be inefficient and have O(n^2) or worse
>>
>>108823531
gr8 b8 m8 i r8 1/8
>>
>>108823328
solid question for video games devs
>>
>>108824187
just integrate it retardo
>>
>>108826859
https://en.wikipedia.org/wiki/Lebesgue_integral

check out this whacky shit
>>
>>108826869
you can also use the paintball integral. whateer.
>>108823328
(defn polygon-area [pts]
(/ (Math/abs (reduce + (map (fn [[[x1 y1] [x2 y2]]] (- (* x1 y2) (* x2 y1)))
(partition 2 1 (conj pts (first pts))))))
2.0))

(defn -main []
(println "Enter vertices as x,y, blank line to finish:")
(printf "Area: %.4f%n"
(polygon-area (->> (repeatedly read-line)
(take-while (complement clojure.string/blank?))
(mapv #(mapv parse-double (clojure.string/split % #",")))))))
>>
>>108823328
ret 0
This program is "simple". If you want something else please
Define make
Define simple
Define program
Define receives
Define coordinates
Define corners
Define polygon
Define input
Define output
Define area
And define the relations, coordinate of corners, corners of a polygon, area of a polygon, and simple program.
>>
>>108823328
>recieves
Indians are getting bolder by the day.
>>
>>108826166
>>108826281
>>108826295
What the fuck are you even trying to say? det is just one of the functions used, you might as well call it an "addition".

If you are looking at the wikipedia entry that is abuse of notation. The fact that the retard defined the determinate of size 2xN as this is both irrelevant and entirely arbitrary.
>>
>>108824990
im sure all that shit will help on your death bed lmao
>>
Not doing your homework for you, Rajesh.
>>
>>108827159
yikes
>>
>>108826601
Is that really a ChatGPTism? I've never heard an LLM say it. Let me update it to "at least that one anon is trying after getting called a retarded faggot"
>>
>>108823328
Just a guess because im lazy
You could start creating a graph of all the edges of the polygon, but for each new node you check if the line created by this and a previous node would cut the line created by two other nodes, and if yes, add a new node at the intersection of the two connecting lines. After you are done you should be able to identify all closed loops, and the area of the polygon should be the sum of the area of said closed loops. Im assuming finding the area of a polygon is trivial, of it isnt you can always divide them into triangles and add the area of the triangles.
>>
never coded in my life. ez

```def polygon_area(points):
"""
Calculate the area of a polygon using the Shoelace formula.
points: list of (x, y) tuples, in clockwise or counterclockwise order.
"""
n = len(points)
if n < 3:
return 0.0 # Not a polygon

area = 0.0
for i in range(n):
x1, y1 = points[i]
x2, y2 = points[(i + 1) % n] # Wrap around to first point
area += x1 * y2 - x2 * y1

return abs(area) / 2.0


# Simple interactive input
print("Enter the number of corners (vertices):")
n = int(input().strip())

print("Enter the coordinates as x y pairs (one per line):")
points = []
for _ in range(n):
line = input().strip()
x, y = map(float, line.split())
points.append((x, y))

area = polygon_area(points)
print(f"\nThe area of the polygon is: {area}")```
>>
>>108829021
You've never heard "You're right to push back on that"? That's what they always say when you call them out on some bullshit
>>
Check the edges for intersection
add new vertices at each intersection
throw it all into a dcel
for each face, if it is inside of the polygon
apply shoelace formula
accumulate

Does this work? [spoiler]I won't try to code it because when I tried writing a dcel from scratch in undergrad it was hard as fuck and I never managed to fix all the bugs[/spoiler]
>>
>>108823328
Make list of lines.
For each pair of lines find intersections. Split any straight lines with intersections into two lines.
From the list of lines, find a closed loop with no lines inside.
Calculate the area of this loop by subdividing it into triangles.
Remove any lines from this loop that do not have at least two neighbors at each end.
Find another closed loop and repeat.
Stop when less than 3 lines remain.
This assumes the polygon does not invert itself. That is: any closed area is positive area.
Did I get the job?
>>
File: Screenshot.png (114 KB, 2010x834)
114 KB PNG
>>108823328
how are you supposed to deal with this stuff?
>>
>>108832690
see >>108823598 and >>108823645
>>
>>108823328
I wrote that exact function once.
The mathematics is surprisingly simple.
>>
File: polygnome.png (12 KB, 578x834)
12 KB PNG
>>108832690
Pro tip: you don't. In situation like that, you cheat.
>>
File: 1759929020306080.gif (65 KB, 636x630)
65 KB GIF
>>108823328
I can't
>>
>>108832989
Don't cry Pepe. It was a trick question.
Don't you know Kurisu is a troll and also a virgin?
>>
File: 1598558080144.png (20 KB, 450x420)
20 KB PNG
>>108823328
best I can do is a statistical estimate via simulation
>>
>>108823406
you will never date an anime girl like her
>>
>>108823406
you will never win her favor if you don't post so post don't be a basedboy at the bar (bar mitzvah)
>>
>>108823604
oh shit nice, gonna try mathing this later. it'd be good practice since I'm finally learning DEs and matrices
>>
>>108829183
You're right to push back on that — It's not a small mistake; It's a big one. Updating my vocabulary now.
[Memory Saved]
>>
>>108829155
>```def
>``` on 4chin
If this is bait I took it.
>>
It's easy but it's 5am so I will do it tomorrow if I feel like it.
>>
>>108825725
whitneychad
>>
It does the job elegantly but requires the boundary of the polygon being
traversed counter clockwise... (and no self crossing).
```
import math

def length(distance):
return math.sqrt(distance[0]**2 + distance[1]**2)

# s = 1/2(a+b+c), F = \sqrt{ s(s-a)(s-b)(s-c) }
def triangle_area(a, b, c):
s = (a+b+c)/2
return math.sqrt(s*(s-a)*(s-b)*(s-c))

# for absolute area supply the points in postive oriented order
def oriented_polygon_area(points):
area = 0
start = points[0]
start_length = length(start)
last = start
last_length = start_length
new_length = 0
cross_prod = 0
orientation = 0
for p in points[1:]:
side = [p[0]-last[0], p[1]-last[1]]
cross_prod = last[0]*side[1] - last[1]*side[0]
orientation = 1 if (cross_prod >= 0) else -1
new_length = length(p)
area += orientation * triangle_area(last_length, new_length, length(side))
last_length = new_length
last = p
# connect the end to the start
side = [start[0]-last[0], start[1]-last[1]]
cross_prod = last[0]*side[1] - last[1]*side[0]
orientation = 1 if (cross_prod >= 0) else -1
area += orientation * triangle_area(last_length, start_length, length(side))
return area

# testing

# area should be 450
figure1 = [
[10, 0],
[20, 0],
[20, 50],
[10, 40]
]

figure2 = [
[10, 0],
[20, 0],
[20, 50],
[15, 100],
[10, 40]
]

def test1():
area = main.oriented_polygon_area(figure1)
print(area)
figure1.reverse()
area = main.oriented_polygon_area(figure1)
print(area)

if __name__ == "__main__":
test1()
```
>>
>>108835989
oopsie
import math

def length(distance):
return math.sqrt(distance[0]**2 + distance[1]**2)

# s = 1/2(a+b+c), F = \sqrt{ s(s-a)(s-b)(s-c) }
def triangle_area(a, b, c):
s = (a+b+c)/2
return math.sqrt(s*(s-a)*(s-b)*(s-c))

# for absolute area supply the points in postive oriented order
def oriented_polygon_area(points):
area = 0
start = points[0]
start_length = length(start)
last = start
last_length = start_length
new_length = 0
cross_prod = 0
orientation = 0
for p in points[1:]:
side = [p[0]-last[0], p[1]-last[1]]
cross_prod = last[0]*side[1] - last[1]*side[0]
orientation = 1 if (cross_prod >= 0) else -1
new_length = length(p)
area += orientation * triangle_area(last_length, new_length, length(side))
last_length = new_length
last = p
# connect the end to the start
side = [start[0]-last[0], start[1]-last[1]]
cross_prod = last[0]*side[1] - last[1]*side[0]
orientation = 1 if (cross_prod >= 0) else -1
area += orientation * triangle_area(last_length, start_length, length(side))
return area

# testing

# area should be 450
figure1 = [
[10, 0],
[20, 0],
[20, 50],
[10, 40]
]

figure2 = [
[10, 0],
[20, 0],
[20, 50],
[15, 100],
[10, 40]
]

def test1():
area = main.oriented_polygon_area(figure1)
print(area)
figure1.reverse()
area = main.oriented_polygon_area(figure1)
print(area)

if __name__ == "__main__":
test1()
>>
Based on the challenge written on the whiteboard in the image, here is a Python program that calculates the area of a polygon given the coordinates of its corners.

To solve this efficiently, the program uses the **Shoelace Formula** (also known as Gauss's area formula), which finds the area of a polygon whose vertices are described by their Cartesian coordinates in the plane.

Here is the code:

```python
def polygon_area(coords):
"""
Calculates the area of a polygon given its corner coordinates.

:param coords: List of tuples/lists containing (x, y) coordinates of the corners
in order (either clockwise or counter-clockwise).
:return: The area of the polygon.
"""
n = len(coords)
area = 0.0

for i in range(n):
# Get the next coordinate index, wrapping around to 0 at the end
j = (i + 1) % n

# Apply the Shoelace formula
area += coords[i][0] * coords[j][1]
area -= coords[j][0] * coords[i][1]

return abs(area) / 2.0

# --- Test Cases ---

# Test with a 2x2 square
square_coords = [(0, 0), (0, 2), (2, 2), (2, 0)]
print(f"Square Area: {polygon_area(square_coords)}")

# Test with a triangle (base 4, height 3)
triangle_coords = [(0, 0), (4, 0), (2, 3)]
print(f"Triangle Area: {polygon_area(triangle_coords)}")
```

### How it works:
1. It iterates through the list of vertices.
2. It multiplies the *x*-coordinate of the current vertex by the *y*-coordinate of the next vertex and adds it to a running total.
3. It multiplies the *y*-coordinate of the current vertex by the *x*-coordinate of the next vertex and subtracts it from the total.
4. Finally, it takes the absolute value of the total and divides it by 2 to get the area.
>>
https://pastebin.com/dan21bzZ
>>
>>108823328
>tranime
No
>>
>>108836218
You will NEVER make it out of Hyderabad
https://pastebin.com/daJ40PMv
>>
File: 1633927458531.png (660 KB, 1076x806)
660 KB PNG
>all the solutions in this thread are in python
>>
>>108836555
What's the problem?
>>
>>108836555
I wrote mine in Python because I was lazy and it's basically psuedocode. I'm more annoyed at how there isn't even an attempt to obfuscate their LLM usage or even use code blocks. I will contribute a solution in emacs lisp later if this thread doesn't die. I translated my Python code into elisp, but I feel like it's probably a gross solution for lisp enjoyers.
(defun my-function (&rest coords)
(let ((total 0)
(n (length coords)))
(dotimes (i n)
(let* ((p1 (nth i coords))
(p2 (nth (mod (+ i 1) n) coords))
(x1 (car p1))
(y1 (cadr p1))
(x2 (car p2))
(y2 (cadr p2)))
(setq total (+ total (- (* x1 y2)
(* y1 x2))))))
(/ (abs total) 2.0)))
my-function

(my-function '(0 0) '(4 0) '(4 5) '(0 5))
20.0
>>
>>108838868 (me)
I just ran this in an interactive shell in Emacs and I did ask AI for some points to test it with + some advice when I got stuck. Going to use it to figure out a more idiomatic version later and not rely on AI as much for the real one.
>>
>>108836555
Buuuu fucking huuuu
Its just pseudo code... And if you have a solution writing it in a faster language does not change the solution itself.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.