Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for Support and Testing.
Download
128 views
ubuntu2204-dev
Kernel: SageMath 9.8

This is from Henri Girad on the sage-support list.

I was trying chatgpt and noticed I was able things I couldn't do myself alone, I think it can help in learning sage because it's a good tool (i am making advert for it lol)

I needed some times to obtain what I wanted and as it gives python sometimes there are mistakes with sage, in graphic I prefer sage libs because I know them better than matplotlib with numpy

from sage.all import * vertices = [(0, 0), (0, 1), (1, 1), (1, 0)] p = polygon(vertices, fill=False) def rotate_point(point, angle): rot = matrix([[cos(angle), sin(angle)], [-sin(angle), cos(angle)]]) return rot * vector(point) theta1 = pi / 4 theta2 = pi / 2 rotated_vertices1 = [rotate_point(vertex, theta1) for vertex in vertices] rotated_vertices2 = [rotate_point(vertex, theta2) for vertex in vertices] # Carré en bas à droite square_bottom_right = [rotate_point((x + 1, y), theta2) + vector([1, 1]) for x, y in vertices] # Carré en haut à droite square_top_right = [rotate_point((x + 1, y + 1), theta2) + vector([0, 2]) for x, y in vertices] # Centrer le losange center = vector([0.05, 0.05]) offset = vector([0.245, -0.05]) # Ajuster l'offset selon les besoins rotated_vertices_centered = [vertex + center + offset for vertex in rotated_vertices1] show(p + polygon(rotated_vertices_centered, fill=False, color='red') + polygon(rotated_vertices2, fill=False, color='blue') + polygon(square_bottom_right, fill=False, color='green') + polygon(square_top_right, fill=False, color='purple'), gridlines="major", axes=False, figsize=5)
Image in a Jupyter notebook