Hi Folks,
I was interested in creating a complex shape to make a moving unit that creates doodads around them look less boring then just a straight rectangle and I stumbled across this post and this tutorial
I managed to get Daelin's example working from the tutorial link to draw a Cuspoid ok in Jass he had an example in GUI that i converted ok.
He had the formulas for drawing some other complex objects but no implementations so I was trying to convert from my bad maths to working shapes.
You can see from the image that it has the text displayed correctly in the centre of the shape and the shape is correct too for an added bonus
I've managed to get Astroid, Cardiod and Nephroid to draw correctly but they centre in the wrong position and my Lemniscate is very wrong i think could anyone with some better Jass or mostly Maths skills take a look and tell me how to fix my code please
The shapes other than Lemniscate seem correct but they are way off centre position for some reason I probably have some sign around the wrong way or converted the formulas incorrectly.
i.e.
The shape is correct but the centre point is outside the shape entirely above the top right corner ( I also failed in the screenshot since its not even visible but trust me it exists heh )
The formulas are above each function as how I interpreted them from the original tutorial from Daelin (tutorial same link as above)
I've attached my test map for this the main code is in the "map-specific custom script code" area
The Functions that I am hoping someone can check over are;
Additional bonus if anyone knows of a way to detect whether a point is inside any of these areas? I could use the angle i guess from the centre point to the point in question then increment out from the centre point and if i hit the desired point before one of the dummies its inside otherwise outside, does that sound feasible?
I was interested in creating a complex shape to make a moving unit that creates doodads around them look less boring then just a straight rectangle and I stumbled across this post and this tutorial
I managed to get Daelin's example working from the tutorial link to draw a Cuspoid ok in Jass he had an example in GUI that i converted ok.
He had the formulas for drawing some other complex objects but no implementations so I was trying to convert from my bad maths to working shapes.
You can see from the image that it has the text displayed correctly in the centre of the shape and the shape is correct too for an added bonus
JASS:
/*
[url]http://www.thehelper.net/threads/graphics-static-shapes-gui.33870/[/url]
deltoid (three cusps hypocycloid)
x=[2/3 cos? – 1/3 cos(2?)] * radius
y=[2/3 sin? + 1/3 sin(2?)] * radius
*/
function Draw_Cuspoid takes player owner, integer unitType, location centre, real radius returns nothing
local real twoThirds = 2.0 / 3.0
local real oneThird = 1.0 / 3.0
local real X = 0
local real Y = 0
local real angle = 0
local real centreX = GetLocationX(centre)
local real centreY = GetLocationY(centre)
local integer index = 1
local location tempPosition
call FloatTextAtPoint(centre, "Cuspoid")
loop
exitwhen index > 50
set angle = ((360 / 50) * I2R(index))
set X = (((twoThirds) * (Cos(angle))) - ((oneThird) * (Cos((2.00 * angle)))))
set X = (X * radius) + centreX
set Y = (((twoThirds) * (Sin(angle))) + ((oneThird) * (Sin((2.00 * angle)))))
set Y = (Y * radius) + centreY
set tempPosition = Location(X,Y)
call CreateUnit( owner, unitType, X, Y, AngleBetweenPoints(centre,tempPosition))
call RemoveLocation(tempPosition)
set index = index + 1
endloop
endfunction
The shapes other than Lemniscate seem correct but they are way off centre position for some reason I probably have some sign around the wrong way or converted the formulas incorrectly.
i.e.
The shape is correct but the centre point is outside the shape entirely above the top right corner ( I also failed in the screenshot since its not even visible but trust me it exists heh )
JASS:
/*
[url]http://www.thehelper.net/threads/graphics-static-shapes-gui.33870/[/url]
Astroid (4 cusps hypocycloid)
x= x0 + radius * cos^3(angle) = x0 + radius * cos(angle) * cos(angle) * cos(angle)
y= y0 + radius * sin^3(angle) = y0 + radius * sin(angle) * sin(angle) * sin(angle)
*/
function Draw_Astroid takes player owner, integer unitType, location centre, real radius returns nothing
local real X = 0
local real Y = 0
local real x0 = 0
local real y0 = 0
local real angle = 0
local real centreX = GetLocationX(centre)
local real centreY = GetLocationY(centre)
local integer index = 1
local location tempPosition
call FloatTextAtPoint(centre, "Astroid")
loop
exitwhen index > 50
set angle = ((360 / 50) * I2R(index))
set X = (x0 + (radius * Pow(Cos(angle),3))) + centreX
set Y = (y0 + (radius * Pow(Sin(angle),3))) + centreY
if(index == 1) then
set x0 = X
set y0 = Y
else
set tempPosition = Location(X,Y)
call CreateUnit( owner, unitType, X, Y, AngleBetweenPoints(centre,tempPosition))
call RemoveLocation(tempPosition)
endif
set index = index + 1
endloop
endfunction
I've attached my test map for this the main code is in the "map-specific custom script code" area
The Functions that I am hoping someone can check over are;
- Draw_Lemniscate
- Draw_Nephroid
- Draw_Cardiod
- Draw_Astroid
Additional bonus if anyone knows of a way to detect whether a point is inside any of these areas? I could use the angle i guess from the centre point to the point in question then increment out from the centre point and if i hit the desired point before one of the dummies its inside otherwise outside, does that sound feasible?
Attachments
Last edited: